How can I change the focus color of a selected element in WatchOS7 with swiftUI. Here’s my example below with a Picker whose focus color is green (the default one) but I want to change it to blue to be consistant with my app layout.
I search over the internet and stackoverflow but did not find andy solution to this. Is it possible to do it in SwiftUI.
3
Answers
Maybe you should try using
.accentColor
modifier to the picker.That’s the focus color and you cannot change it. At least no with standard view modifiers like
.accentColor
,.tint
, etc.You can try to hide it by overlying another view (like in this response), for example, or try to reach to UIKit using instrospection.
Probably it’s best to be at peace with the fact that it’s system behavior.
If you don’t mind building your own picker-type view, you can use
.digitalCrownRotation()
instead of the picker as discussed here in regards to hiding the border: https://stackoverflow.com/a/75909943/21505031Example code here: https://www.hackingwithswift.com/quick-start/swiftui/how-to-read-the-digital-crown-on-watchos-using-digitalcrownrotation