I'm attempt to change the tint color of all my toggles within my app to blue. I tried using both UISwitch.appearance().tintColor and UISwitch.appearance().onTintColor with no help.
import SwiftUI
@main
struct Studently: App {
init() {
UISwitch.appearance().tintColor = .systemBlue
UISwitch.appearance().onTintColor = .systemBlue
}
var body: some Scene {
WindowGroup {
TabBar()
}
}
}
Image: .onTintColor and .tintColor does nothing in another view
The weird thing is, if the state property wrapper is true, the color will be applied. But once toggled to off then on, it returns back to standard green.
Image: Color only applied if the state property wrapped is set to true
I thought maybe this was just a human error on my end. So I tested this out more using UISwitch.appearance.thumbTintColor which applies to a toggle within another view.
@main
struct Studently: App {
init() {
UISwitch.appearance().tintColor = .systemBlue
UISwitch.appearance().onTintColor = .systemBlue
UISwitch.appearance().thumbTintColor = .red
}
var body: some Scene {
WindowGroup {
TabBar()
}
}
}
Image: .thumbTintColor changes the circle to red
.thumbTintColor is just for example that it can be applied, but neither .tintColor or .onTintColor are applied.
Of course, using .tint works when applied to a single toggle, but I want this to apply to all Toggles without using .tint on each one.
How can I achieve or fix this?