Code: Select all
import SwiftUI
struct HomeScreenCounterView: View {
private let value: Int
private let title: String
private let emptyDescription: String
init(value: Int, title: String, emptyDescription: String) {
self.value = value
self.title = title
self.emptyDescription = emptyDescription
}
var body: some View {
VStack {
Text("Messages")
.font(.fontTextLBold)
Text("No new messages")
.font(.fontTextSRegular)
}
.padding()
.clipShape(RoundedRectangle(cornerRadius: 16))
}
}
#Preview {
HomeScreenCounterView(value: 0,
title: "Messages",
emptyDescription: "No new messages")
.foregroundStyle(Color.red)
.background(Color.blue)
}
< /p>
Beachten Sie, wie die Textfarbe in beiden Etiketten in Rot geändert wurde. Als blau angezeigt, wird es offensichtlich nicht abgeschnitten, da der Clipping -Operator früher und nicht später angewendet wurde. Ähnlich wie die anderen Swiftui -Komponenten funktionieren? />
Code: Select all
init(value: Int, title: String, emptyDescription: String, backgroundColor: Color) {
.padding()
.background(backgroundColor)
.clipShape(RoundedRectangle(cornerRadius: 16))
< /code>
Aber gibt es einen besseren Weg? = "Bildbeschreibung hier eingeben" src = "https://i.sstatic.net/zllv1o6m.png"/>