5

在 a 中选择列表项时,如何更改其背景颜色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())
}

在此处输入图像描述

4

1 回答 1

1

只需使用.accentColor,如下

在此处输入图像描述

List (templateModel.model.items) { item in

    // ... other content here

}
.accentColor(.gray)       // << here !!
于 2020-09-20T11:14:20.513 回答