Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to opt-out of dark mode on iOS 13?

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?

like image 811
SeanR Avatar asked Jun 11 '19 06:06

SeanR


People also ask

How do I permanently turn off dark mode on my iPhone?

Now, as of the latest iOS 15 beta, it's possible to permanently turn off the feature. To turn it off, you'll need to go to Settings > Camera > Preserve Settings then toggle on the setting for Night Mode. This will ensure the next time you turn off Night Mode, it will stay off until you turn it back on.

How do I force light in iOS?

iOS Simulator can toggle between light and dark mode with ⌘ - command + ⇧ - shift + a shortcut.


2 Answers

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:

Entire app via info.plist file (Xcode 12)

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


Entire app via info.plist in build settings (Xcode 13)

enter image description here


Entire app window via window property

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 } 

Individual UIViewController or UIView

You can set overrideUserInterfaceStyle against the UIViewControllers 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


Individual views via SwiftUI View

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.

like image 119
CodeBender Avatar answered Sep 23 '22 03:09

CodeBender


According to Apple's session on "Implementing Dark Mode on iOS" (https://developer.apple.com/videos/play/wwdc2019/214/ starting at 31:13) it is possible to set overrideUserInterfaceStyle to UIUserInterfaceStyleLight or UIUserInterfaceStyleDark on any view controller or view, which will the be used in the traitCollection for any subview or view controller.

As already mentioned by SeanR, you can set UIUserInterfaceStyle to Light or Dark in your app's plist file to change this for your whole app.

like image 41
dorbeetle Avatar answered Sep 21 '22 03:09

dorbeetle