Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS UIAlertController Dark Theme

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.

like image 898
XvKnightvX Avatar asked Aug 23 '16 21:08

XvKnightvX


1 Answers

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+

like image 124
Aditi Patil Avatar answered Oct 09 '22 14:10

Aditi Patil