A large part of my app consists of web views to provide functionality not yet available through native implementations. The web team has no plans to implement a dark theme for the website. As such, my app will look a bit half/half with Dark Mode support on iOS 13.
Is it possible to opt out of Dark Mode support such that our app always shows light mode to match the website theme?
If your iPhone is up-to-date, chances are your phone's brightness sometimes changes automatically. This can be due to Auto-Brightness – a feature that adjusts your screen's brightness based on how much light is around you so you can see better.
To control an interface style for an entire app, you simply set UIUserInterfaceStyle (Appearance) key in your Info. plist file. You can assign it to either Light or Dark value to force a light and dark user interface style. Set Appearance (UIUserInterfaceStyle) key to Light will disable dark mode for an entire app.
In the menu that opens after clicking “Settings,” select “Search Settings.” You will arrive on the “Search Settings” page. Here, in the left sidebar, click “Appearance.” In the “Appearance” section on the right, enable the “Light Theme” option.
First, here is Apple's entry related to opting out of dark mode. The content at this link is written for Xcode 11 & iOS 13:
Use the following key in your info.plist file:
UIUserInterfaceStyle
And assign it a value of Light
.
The XML for the UIUserInterfaceStyle
assignment:
<key>UIUserInterfaceStyle</key> <string>Light</string>
Apple documentation for UIUserInterfaceStyle
You can set overrideUserInterfaceStyle
against the app's window
variable. This will apply to all views that appear within the window. This became available with iOS 13, so for apps that support previous versions, you must include an availability check.
Depending on how your project was created, this may be in the AppDelegate
or SceneDelegate
file.
if #available(iOS 13.0, *) { window?.overrideUserInterfaceStyle = .light }
You can set overrideUserInterfaceStyle
against the UIViewController
s or UIView
's overrideUserInterfaceStyle
variable. This became available with iOS 13, so for apps that support previous versions, you must include an availability check.
Swift
override func viewDidLoad() { super.viewDidLoad() // overrideUserInterfaceStyle is available with iOS 13 if #available(iOS 13.0, *) { // Always adopt a light interface style. overrideUserInterfaceStyle = .light } }
For those poor souls in Objective-C
if (@available(iOS 13.0, *)) { self.overrideUserInterfaceStyle = UIUserInterfaceStyleLight; }
When set against the UIViewController
, the view controller and its children adopt the defined mode.
When set against the UIView
, the view and its children adopt the defined mode.
Apple documentation for overrideUserInterfaceStyle
You can set preferredColorScheme
to be either light
or dark
. The provided value will set the color scheme for the presentation.
import SwiftUI struct ContentView: View { var body: some View { Text("Light Only") .preferredColorScheme(.light) } }
Apple documentation for preferredColorScheme
Credit to @Aron Nelson, @Raimundas Sakalauskas, @NSLeader and @rmaddy for improving this answer with their feedback.
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