设置 listRowBackground 似乎没有任何作用。我尝试将其设置为行和列表,但没有运气
主屏幕
struct FAQView: View {
var body: some View {
List(FAQ.all) {
FAQRow(faq: $0)
.listRowBackground(Color.pink)
}
}
}
Run Code Online (Sandbox Code Playgroud)
排
struct FAQRow: View {
private let faq: FAQ
init(faq: FAQ) {
self.faq = faq
}
var body: some View {
VStack(alignment: .leading) {
Text(faq.question)
.foregroundColor(.purple)
.multilineTextAlignment(.leading)
ZStack {
Text(faq.answer)
.foregroundColor(.secondary)
.multilineTextAlignment(.leading)
.padding(EdgeInsets(top: Spacing.smallViewSpacing, leading: Spacing.smallViewSpacing, bottom: Spacing.smallViewSpacing, trailing: Spacing.smallViewSpacing))
}
.background(Color.green)
.cornerRadius(15)
.padding(EdgeInsets(top: 10, leading: 10, bottom: 10, trailing: 10))
}
}
}
Run Code Online (Sandbox Code Playgroud)
使用ForEach
该
struct FAQView: View {
var body: some View {
List {
ForEach(FAQ.all) {
FAQRow(faq: $0)
}
.listRowBackground(Color.pink) // << here !!
}
}
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
444 次 |
最近记录: |