Reputation: 1341
My app is using AccentColor defined in Assets.xcassets. I set AccentColor to yellow, however ActionSheets are still using default blue color. Color of button changes after button is touched, but resets to blue after sheet is closed and opened again.
struct ContentView: View {
@State private var show = false
var body: some View {
VStack {
Button(action: { show = true }) {
Text("Open")
.actionSheet(isPresented: $show) {
let btns: [ActionSheet.Button] = [
.default(Text(LocalizedStringKey("Button 1")), action: {}),
.destructive(Text(LocalizedStringKey("Button 2")), action: {}),
.default(Text(LocalizedStringKey("Button 3")), action: {}),
.cancel()
]
return ActionSheet(title: Text("Action Sheet"), buttons: btns)
}
}
}
}
}
Upvotes: 2
Views: 148
Reputation: 1341
It looks like a bug (mainly because some actions sheets are rendered with correct color and some are not). I can't find the reason for that, just some sheets are rendered correctly.
Until it's fixed, there is one trick that fixed my problem. It's not perfect, as it's overwrites default tintColor
of UIAlertController
, but it works. It's as simple as using one line of code in SceneDelegate:
// SceneDelegate.swift
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
// ...
// Any color may be used instead of UIColor(named: "AccentColor")
UIView.appearance(whenContainedInInstancesOf: [UIAlertController.self]).tintColor = UIColor(named: "AccentColor")
// ...
}
Upvotes: 1