SwiftUI listRowBackground 似乎不起作用

ary*_*axt 4 ios swift swiftui

设置 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)

Asp*_*eri 6

使用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)