SwiftUI Grouped List Change backgroundColor

818 Views Asked by At

I have a grouped list:

enter image description here

How to change the systemGroupedBackgroundColor of the List? Here is the code:

struct View2: View {
var array = ["1", "2", "3"]

@State private var selected: String?

var body: some View {
    List(array, id:\.self) { value in
        Text("\(value) Navigation 1")
            .listRowBackground(Color.green)
        NavigationLink("", destination: View1())
    }.background(Color.red)
    .listStyle(GroupedListStyle())
    }
}

struct ContentView: View {
    var body: some View {

        NavigationView {
            VStack {
                View2()
            }
        }.navigationBarTitle("Navigation")
    }
}

I've tried set the background of the List to Red, but doesn't work. Like below. Thanks!

enter image description here

1

There are 1 best solutions below

0
On

Insert the following code into View2 and it should work:

init() {
    UITableView.appearance().backgroundColor = .red
}