1

In an iOS app using SwiftUI, I have set an alert with this kind of code:

  Alert(title: Text("Nice Title"),
        message: Text("Some important message for the user."),
        dismissButton: .none)

It works, but I would like to change one detail. The alert has a blue OK button. I want to customize it to have a grey OK button.

I have tried a couple of tweaks, one of them being this:

  Alert(title: Text("Nice Title"),
        message: Text("Some important message for the user."),
        dismissButton: .default(Text("OK").foregroundColor(.gray)))

But none of my trials worked.

If anyone knows the way to go, please let me know.

Michel
  • 10,303
  • 17
  • 82
  • 179
  • It's something that with the current version of swiftUI you can't do it yet. It could be possible with beta xcode presented at wwdc and ios 14 – Joannes Jul 07 '20 at 07:46
  • dismissButton expects an Alert.Button. There are only a few available which take an Text() .. so no chance to style it with background. The only option might be creating an own Alert.Button. Not sure, if it is possible with extension – davidev Jul 07 '20 at 09:10

1 Answers1

0

put this in the view that shows z alert

    init() {
        UIView.appearance(whenContainedInInstancesOf: [UIAlertController.self]).tintColor = .purple1
    }
aaronium112
  • 2,992
  • 4
  • 35
  • 50