I’ve defined a custom accent color for light and dark mode. When using light mode the accent color should be black and in dark mode white.
When using light mode everything works fine:
But when turning dark appearance on, the selection color for the list item isn’t working as expected.
What am I missing? Why does the selection not invert in dark mode? The provided screenshots are related to the simulator in macOS.
Many thanks!
Update:
As asked by @son the code for the selection
List(selection: $appState.selectedDetail) {
ForEach(listItems) { item in
HStack {
Text("(item.startDate.formatDate())")
Text("-")
Text("(item.endDate.formatDate())")
}
.tag(DetailSelection.item(item: item))
.monospaced()
}
}
2
Answers
You get the environment color scheme and set the text color according to the current scheme.
I followed the instructions for specifying an accent color and it works for me:
There are two main steps: