iOS 14, Swift UI 2 change background color of selected List item inside a NavigationLink

Viewed 1261

How can I change the background color of a list item while it is selected inside of a NavigationLink?

It is always highlighted in blue (see the attached screen). I tried to change the listRowBackgroundColor view modifier, but it didn't work.

NavigationView {
    
    List (templateModel.model.items) { item in
        
        NavigationLink(destination: DetailView(selectedCategory: item.name, dismiss: dismiss)
            .environmentObject(OrientationInfo())) {
             Text("Test")
                 .listRowBackground(Color.gray)
        }
        .background(Color.black)
        .buttonStyle(PlainButtonStyle())
        .listRowBackground(Color.gray)
    }    
    .background(Color.black) 
    .listStyle(InsetListStyle())
}

enter image description here

1 Answers

Just use .accentColor, as below

enter image description here

List (templateModel.model.items) { item in

    // ... other content here

}
.accentColor(.gray)       // << here !!
Related