Selection color of a NavigationLink in List was different in Simulator and Device (SwiftUI)
I have a list with some NavigationLinks as OutlineGroup:
List {
OutlineGroup(bundle.topics, children: \.children) { topic in
NavigationLink(destination: DetailView(topic: topic)) {
Label(topic.name, systemImage: topic.children != nil ? "folder" : "doc")
}
}
}
My problem is that the selection color was different on the iPad Air device and the iPad Air simulator. On the simulator, the background color of a selected NavigationLink was gray and the disclosure indicator is still visible.
But on the real iPad Air device, the selection color is blue – the same blue as the disclosure indicator and it wasn't visible on a selected row.
Any idea, why the color is difference? Can I manually set the selection background color?
Add an accentColor(_:)
modifier to the list with the color you want to use.
List {
OutlineGroup(bundle.topics, children: \.children) { topic in
NavigationLink(destination: DetailView(topic: topic)) {
Label(topic.name, systemImage: topic.children != nil ? "folder" : "doc")
}
}
}
.accentColor(.gray)
The only problem is accentColor(_:)
is getting deprecated. Apple suggests to use tint(_:)
but it isn't working. The other option would be to change the asset catalog’s accent color.