SwiftUI listRowBackground doesn't seem to work

Viewed 1312

Setting listRowBackground doesn't seem to do anything. I tried setting it to the row and to the list with no luck

Main Screen

struct FAQView: View {
    var body: some View {
        List(FAQ.all) {
            FAQRow(faq: $0)
                .listRowBackground(Color.pink)
        }
    }
}

Row

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))
        }
    }
}
1 Answers

Use ForEach for that

struct FAQView: View {
    var body: some View {
        List {
           ForEach(FAQ.all) {
             FAQRow(faq: $0)
           }
           .listRowBackground(Color.pink)    // << here !!
        }
    }
}
Related