'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?



Solution 1:[1]

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.

Solution 2:[2]

If you are not using Xcode 11 or later (i,e iOS 13 or later SDK), your app has not automatically opted to support dark mode. So, there's no need to opt out of dark mode.

If you are using Xcode 11 or later, the system has automatically enabled dark mode for your app. There are two approaches to disable dark mode depending on your preference. You can disable it entirely or disable it for any specific window, view, or view controller.

Disable Dark Mode Entirely for your App

You can disable dark mode by including the UIUserInterfaceStyle key with a value as Light in your app’s Info.plist file.
UIUserInterfaceStyle as Light
This ignores the user's preference and always applies a light appearance to your app.

Disable dark mode for Window, View, or View Controller

You can force your interface to always appear in a light or dark style by setting the overrideUserInterfaceStyle property of the appropriate window, view, or view controller.

View controllers:

override func viewDidLoad() {
    super.viewDidLoad()
    /* view controller’s views and child view controllers 
     always adopt a light interface style. */
    overrideUserInterfaceStyle = .light
}

Views:

// The view and all of its subviews always adopt light style.
youView.overrideUserInterfaceStyle = .light

Window:

/* Everything in the window adopts the style, 
 including the root view controller and all presentation controllers that 
 display content in that window.*/
window.overrideUserInterfaceStyle = .light

Note: Apple strongly encourages to support dark mode in your app. So, you can only disable dark mode temporarily.

Read more here: Choosing a Specific Interface Style for Your iOS App

Solution 3:[3]

********** Easiest way for Xcode 11 and above ***********

Add this to info.plist before </dict></plist>

<key>UIUserInterfaceStyle</key>
<string>Light</string>

Solution 4:[4]

Xcode 12 and iOS 14 update. I have try the previous options to opt-out dark mode and this sentence in the info.plist file is not working for me:

<key>UIUserInterfaceStyle</key>
<string>Light</string>

Now it is renamed to:

<key>Appearance</key>
<string>Light</string>

This setting will block all dark mode in the full app.

EDITED:

Fixed typo thank you to @sarah

Solution 5:[5]

I think I've found the solution. I initially pieced it together from UIUserInterfaceStyle - Information Property List and UIUserInterfaceStyle - UIKit, but have now found it actually documented at Choosing a specific interface style for your iOS app.

In your info.plist, set UIUserInterfaceStyle (User Interface Style) to 1 (UIUserInterfaceStyle.light).

EDIT: As per dorbeetle's answer, a more appropriate setting for UIUserInterfaceStyle may be Light.

Solution 6:[6]

The answer above works if you want to opt out the whole app. If you are working on the lib that has UI, and you don't have luxury of editing .plist, you can do it via code too.

If you are compiling against iOS 13 SDK, you can simply use following code:

Swift:

if #available(iOS 13.0, *) {
    self.overrideUserInterfaceStyle = .light
}

Obj-C:

if (@available(iOS 13.0, *)) {
    self.overrideUserInterfaceStyle = UIUserInterfaceStyleLight;
}

HOWEVER, if you want your code to compile against iOS 12 SDK too (which right now is still the latest stable SDK), you should resort to using selectors. Code with selectors:

Swift (XCode will show warnings for this code, but that's the only way to do it for now as property does not exist in SDK 12 therefore won't compile):

if #available(iOS 13.0, *) {
    if self.responds(to: Selector("overrideUserInterfaceStyle")) {
        self.setValue(UIUserInterfaceStyle.light.rawValue, forKey: "overrideUserInterfaceStyle")
    }
}

Obj-C:

if (@available(iOS 13.0, *)) {
    if ([self respondsToSelector:NSSelectorFromString(@"overrideUserInterfaceStyle")]) {
        [self setValue:@(UIUserInterfaceStyleLight) forKey:@"overrideUserInterfaceStyle"];
    }
}

Solution 7:[7]

For the entire App: (in the info.plist file):

<key>UIUserInterfaceStyle</key>
<string>Light</string>

plist


Window (Usually the whole app):

window!.overrideUserInterfaceStyle = .light

You can get the window from SceneDelegate


UIViewController:

viewController.overrideUserInterfaceStyle = .light

You can set any viewController, even inside the viewController itself


UIView:

view.overrideUserInterfaceStyle = .light

You can set any view, even inside the view itself

You may need to use if #available(iOS 13.0, *) { ,,, } if you are supporting earlier iOS versions.


SwiftUI View:

.preferredColorScheme(.light) <- This Modifier

or

.environment(\.colorScheme, .light) <- This Modifier

Solution 8:[8]

You can turn Dark Mode off in entire application in Xcode 11:

  1. Go Info.plist
  2. Add bellow like

    <key>UIUserInterfaceStyle</key>
    <string>Light</string>
    

Info.plist will be look like below...

enter image description here

Solution 9:[9]

Latest Update-

If you're using Xcode 10.x, then the default UIUserInterfaceStyle is light for iOS 13.x. When run on an iOS 13 device, it will work in Light Mode only.

No need to explicitly add the UIUserInterfaceStyle key in Info.plist file, adding it will give an error when you Validate your app, saying:

Invalid Info.plist Key. The key 'UIUserInterfaceStyle' in the Payload/AppName.appInfo.plist file is not valid.

Only add the UIUserInterfaceStyle key in Info.plist file when using Xcode 11.x.

Solution 10:[10]

iOS 14.3 and Xcode 12.3 Update

In info.plist file add Appearance as Light.

<key>Appearance</key>
<string>Light</string>

Solution 11:[11]

If you will add UIUserInterfaceStyle key to the plist file, possibly Apple will reject release build as mentioned here: https://stackoverflow.com/a/56546554/7524146 Anyway it's annoying to explicitly tell each ViewController self.overrideUserInterfaceStyle = .light. But you can use this peace of code once for your root window object:

if #available(iOS 13.0, *) {
    if window.responds(to: Selector(("overrideUserInterfaceStyle"))) {
        window.setValue(UIUserInterfaceStyle.light.rawValue, forKey: "overrideUserInterfaceStyle")
    }
}

Just notice you can't do this inside application(application: didFinishLaunchingWithOptions:) because for this selector will not respond true at that early stage. But you can do it later on. It's super easy if you are using custom AppPresenter or AppRouter class in your app instead of starting UI in the AppDelegate automatically.

Solution 12:[12]

Apart from other responses, from my understanding of the following, you only need to prepare for Dark mode when compiling against iOS 13 SDK (using XCode 11).

The system assumes that apps linked against the iOS 13 or later SDK support both light and dark appearances. In iOS, you specify the specific appearance you want by assigning a specific interface style to your window, view, or view controller. You can also disable support for Dark Mode entirely using an Info.plist key.

Link

Solution 13:[13]

Swift 5

Two ways to switch dark to light mode:

1- info.plist

    <key>UIUserInterfaceStyle</key>
    <string>Light</string>

2- Programmatically or Runtime

  @IBAction private func switchToDark(_ sender: UIButton){
        UIApplication.shared.windows.forEach { window in
            //here you can switch between the dark and light
            window.overrideUserInterfaceStyle = .dark
        }
    }

Solution 14:[14]

In Xcode 12, you can change add as "appearances". This will work!!

Solution 15:[15]

My app does not support dark mode as of now and uses a light app bar color. I was able to force the status bar content to dark text and icons by adding the following key to my Info.plist:

<key>UIStatusBarStyle</key>
<string>UIStatusBarStyleDarkContent</string>
<key>UIUserInterfaceStyle</key>
<string>Light</string>
<key>UIViewControllerBasedStatusBarAppearance</key>
<true/>

Find the other possible values here: https://developer.apple.com/documentation/uikit/uistatusbarstyle

Flutter Users

Don't forget to set the app bar brightness attribute on your Flutter app bar like this:

AppBar(
    backgroundColor: Colors.grey[100],
    brightness: Brightness.light, // <---------
    title: const Text('Hi there'),
),

Solution 16:[16]

Yes you can skip by adding the following code in viewDidLoad:

if #available(iOS 13.0, *) {
        // Always adopt a light interface style.
        overrideUserInterfaceStyle = .light
    }

Solution 17:[17]

Objective-c version

 if (@available(iOS 13.0, *)) {
        _window.overrideUserInterfaceStyle = UIUserInterfaceStyleLight;
    }

Solution 18:[18]

Add this to info.plist

<key>UIUserInterfaceStyle</key>
    <string>Light</string>

Solution 19:[19]

Yes.. you can add below setting in iOS project.

In info.plist file add UIUserInterfaceStyle to Light.

If your project is in IONIC.. You can add below setting in config file

<platform name="ios">
  <edit-config file="*-Info.plist" mode="merge" target="UIUserInterfaceStyle">
  <string>Light</string>
 </edit-config>
</platform>

Using these settings, device dark mode will not affect your app.

Solution 20:[20]

 if #available(iOS 13.0, *) {
            overrideUserInterfaceStyle = .light
        } else {
            // Fallback on earlier versions
        }

Solution 21:[21]

Here are a few tips and tricks which you can use in your app to support or bypass the dark mode.

First tip: To override the ViewController style

you can override the interface style of UIViewController by

1: overrideUserInterfaceStyle = .dark //For dark mode

2: overrideUserInterfaceStyle = .light //For light mode

class ViewController: UIViewController {
    override func viewDidLoad() {
        super.viewDidLoad()
        overrideUserInterfaceStyle = .light    
    }
}

Second tip: Adding a key in info.plist

Simply you can add a new key

UIUserInterfaceStyle

in your app info.plist and set its value to Light or Dark. this will override the app default style to the value you provide. You don't have to add overrideUserInterfaceStyle = .light this line in every viewController, just one line in info.plist that’s it.

Solution 22:[22]

Just simply add following key in your info.plist file :

<key>UIUserInterfaceStyle</key>
    <string>Light</string>

Solution 23:[23]

Just add these line in info.plist file:

<key>UIUserInterfaceStyle</key>
<string>light</string>

This will force app to run in light mode only.

Solution 24:[24]

add overrideUserInterfaceStyle = .light in ViewController.swift file or change Appearance to "light" in info.plist file

Solution 25:[25]

I would use this solution since window property may be changed during the app life cycle. So assigning "overrideUserInterfaceStyle = .light" needs to be repeated. UIWindow.appearance() enables us to set default value that will be used for newly created UIWindow objects.

import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {

      if #available(iOS 13.0, *) {
          UIWindow.appearance().overrideUserInterfaceStyle = .light
      }

      return true
    }
}

Solution 26:[26]

import UIKit

extension UIViewController {

    override open func awakeFromNib() {

        super.awakeFromNib()

        if #available(iOS 13.0, *) {

            overrideUserInterfaceStyle = .light

        }

    }
}

Solution 27:[27]

You can do: add this new key UIUserInterfaceStyle to Info.plist and set its value to Light. and check alert controller appears with light mode.

UIUserInterfaceStyle Light If you are force light/dark mode in your whole application regardless of the user's settings by adding the key UIUserInterfaceStyle to your Info.plist file and setting its value to either Light or Dark.

Solution 28:[28]

This question has so many answers, rather using it in info.plist you can set it in AppDelegate like this:

#if compiler(>=5.1)
        if #available(iOS 13.0, *) {
            self.window?.overrideUserInterfaceStyle = .light
        }
        #endif

Test on Xcode 11.3, iOS 13.3