I'm working on an app for iOS with a dark theme and I want to use a UIAlertController
. However, the white alert looks out of place. Would it be against the Human Interface Guidelines even on a dark themed app to use a dark themed UIAlertController
(when I say dark themed alert all I mean is switching the white background to a dark grey and the text to white this also includes the buttons).
Assuming it's not against the guidelines how would I go about achieving this? I can't seem to find a theme for the UIAlertController
that would allow this.
With iOS 13, Apple provides Dark Mode. But if your App theme doesn't match with Device Theme, you can set your view controller's theme.
For eg, My Device Appearance is Dark Mode, and my App is always in light mode. But the popups using UIAlertController are following Device Theme, Dark theme, and a black popup over my white screen doesn't match.
Solution #1: Inline Solution
While creating the UIAlertController, I can set its theme
alert.overrideUserInterfaceStyle = UIUserInterfaceStyleLight;
Solution #2: Support for Whole App
In you AppDelegate, set the theme for window
self.window.overrideUserInterfaceStyle = UIUserInterfaceStyleLight;
This will cause all the popups to use light theme.
Note: UIAlertView won't use the dark/light theme if you set its overrideUserInterfaceStyle property.
Also, don't forget to add if #available(iOS 13.0, *)
check before setting the property, as it is available only in iOS 13+
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With