iOS 14,Swift UI 2更改NavigationLink中选定列表项的背景颜色

问题描述

NavigationLink中选中列表项时,如何更改其背景颜色?

它始终以蓝色突出显示(请参见所附屏幕)。我试图更改listRowBackgroundColor视图修饰符,但是没有用。

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

解决方法

只需使用.accentColor,如下所示

enter image description here

List (templateModel.model.items) { item in

    // ... other content here

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