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

212,274

Solution 1

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.

Solution 2

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 3

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 4

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

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

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

Solution 5

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

Share:
212,274
SeanR
Author by

SeanR

Updated on July 18, 2022

Comments

  • SeanR
    SeanR almost 2 years

    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?

    • Tieme
      Tieme almost 5 years
      Set UIUserInterfaceStyle to Light in your Info.Plist. See developer.apple.com/library/archive/documentation/General/…
    • user3741598
      user3741598 almost 5 years
      Thanks for asking - for all of us. A lot of apps to go through. This is needed to keep apps working until the toggle is ready.
    • Mohammad Razipour
      Mohammad Razipour almost 5 years
      import Foundation import UIKit extension UIViewController { override open func awakeFromNib() { super.awakeFromNib() if #available(iOS 13.0, *) { // Always adopt a light interface style. overrideUserInterfaceStyle = .light } } }
    • Fattie
      Fattie over 4 years
      simply add UIUserInterfaceStyle in plist. it's that easy
    • kiran
      kiran over 4 years
      While submitting app to appstore do apple accept due to UIUserInterfaceStyle in Light mode.
    • benc
      benc about 4 years
      @kiran - Yes, just did it for a TF build.
    • Shrikant Phadke
      Shrikant Phadke over 3 years
      I think we can not disable permission popups and other system alerts. does anyone have a solution for this or is it impossible because os manages it?
  • funkenstrahlen
    funkenstrahlen about 5 years
    Enforcing dark mode by setting the value to 2 does not work though: [UIInterfaceStyle] '2' is not a recognized value for UIUserInterfaceStyle. Defaulting to Light.
  • Aron Nelson
    Aron Nelson almost 5 years
    UIUserInterfaceStyle light is blocked when updating/uploading your app now. It gets flagged as an invalid plist entry. (Invalid plist key)
  • Raimundas Sakalauskas
    Raimundas Sakalauskas almost 5 years
    This won't compile against iOS SDK 12 (currently latest stable SDK). See stackoverflow.com/a/57521901/2249485 for solution that will work with iOS 12 SDK too.
  • Sonius
    Sonius almost 5 years
    If you set the UIUserInterfaceStyle key your app will be rejected in App store
  • José
    José almost 5 years
    Having this key in the plist will result in an App Store rejection.
  • PRASAD1240
    PRASAD1240 almost 5 years
    Apple rejected with ITMS-90190 error code forums.developer.apple.com/thread/121028
  • dorbeetle
    dorbeetle almost 5 years
    The rejection is most likely to happen because the iOS 13 SDK is not yet out of beta. I think this should work as soon as the Xcode 11 GM is available.
  • steven
    steven almost 5 years
    @dorbeetle it's not true, I uploaded my app with this key successfully like 1 month ago with Xcode 10. The rejections happen recently. It seems some kinds of new Apple strategy.
  • dpart
    dpart almost 5 years
    Its weird to hear about rejection. Regarding ios 13 documentation it says set the "UIUserInterfaceStyle" key in your Info.plist.
  • raven_raven
    raven_raven almost 5 years
    You are not out of luck when it comes to controling UIColor behaviour, as discussed in this question: stackoverflow.com/questions/56487679/…
  • Niranjan Molkeri
    Niranjan Molkeri almost 5 years
    This has nothing to do with Xcode 10 or 11. If user deployes app form Xcode 10 and doesn't take care of dark mode, the app when installed in iPhone 11, Pro or Pro Max it will have dark mode issues. you need to update to Xcode 11 and address this issue.
  • kumarsiddharth123
    kumarsiddharth123 almost 5 years
    @NiranjanMolkeri This has nothing to do with newer iPhones. It's about Dark mode on iOS 13. In previous iOS 13 beta version apps UI were having dark mode issues if not handled explicitly. But in the latest version, that is fixed. If you're using XCode 10, then the default UIUserInterfaceStyle is light for iOS13. If you're using Xode11 you need to handle it.
  • Raimundas Sakalauskas
    Raimundas Sakalauskas almost 5 years
    This is so unfair that the question that has much more views than "original question" is locked for providing answers. :(
  • thisIsTheFoxe
    thisIsTheFoxe almost 5 years
    I just uploaded with the .plist entry and it went through.. very interested how the review will take it... hmmm
  • rmaddy
    rmaddy almost 5 years
    Instead of setting overrideUserInterfaceStyle in viewDidLoad of every view controller, you can set it once on the main window of the app. So much easier if you want the whole app to behave one way.
  • Evgen Bodunov
    Evgen Bodunov almost 5 years
    It's still happening. Xcode GM2 returned app signing error. Xcode 10.3 returned: "Invalid Info.plist Key. The key 'UIUserInterfaceStyle' in the Payload/Galileo.appInfo.plist file is not valid."
  • Bek
    Bek almost 5 years
    I assume that the App Store error posted above was a bug on Apple's part. I just uploaded an app today with that plist key and it went through fine.
  • Bek
    Bek almost 5 years
    Xcode 11.0 (11A420a) downloaded from app store (not GM seed).
  • CodeBender
    CodeBender almost 5 years
    @Bek Ok, sorry I was not explicit with it, but that error message only pertains to Xcode 10.
  • NSLeader
    NSLeader almost 5 years
    Use #if compiler(>=5.1) instead responds(to:) and setValue
  • nickdnk
    nickdnk almost 5 years
    AppStore no longer rejects this property in plist.info. I put "Dark" (capitalized) since our app is already dark. No problems. This properly lets us use the system controls.
  • DawnSong
    DawnSong almost 5 years
    @nickdnk I think you built your app with Xcode 11, which is recommended by Apple.
  • nickdnk
    nickdnk almost 5 years
    Yes, I did. It doesn't change the fact that Apple does accept this parameter in the plist, which was what I was trying to make clear.
  • DawnSong
    DawnSong almost 5 years
    It will be better if you specify to what the property overrideUserInterfaceStyle belongs.
  • Rohit Funde
    Rohit Funde over 4 years
    how about status bar style ? its showing white in dark mode
  • Jeroen
    Jeroen over 4 years
    @thisIsTheFoxe Any update? I'm curious if I could use this for our live apps as we don't have plans to support it yet, and parts of our app are 'breaking', for example tableViews getting a dark background while the text is dark as well.
  • thisIsTheFoxe
    thisIsTheFoxe over 4 years
    @JeroenJK I think you should be fine. If you look you should also be able to opt-out straight from the Storyboard so it shouldn't be impossible to get past AS-review. But you definitely should consider it - imo :)
  • Jeroen
    Jeroen over 4 years
    Yes, I successfully deployed new versions of our apps. :-)
  • Tawfik Bouabid
    Tawfik Bouabid over 4 years
    this solution will fail when from submitting the app on Xcode 10.x
  • eharo2
    eharo2 over 4 years
    You will have issues if you upload an app to TestFligth using Xcode 10.3 and the plist includes the key UIUserInterfaceStyle. It will say that it is an invalid plist file. You have to either remove it if building in Xcode 10, or uploading using Xcode 11
  • 7xRobin
    7xRobin over 4 years
    I tried to modify for the entire application with xcode 10.5. But got "Function-like macro 'compiler' is not defined".
  • Jeroen
    Jeroen over 4 years
    This was already commented and answered many times. Even the accepted answer is suggesting this. Therefore this comment doesn't add any new information.
  • Arun Vinoth - MVP
    Arun Vinoth - MVP over 4 years
    Can you explain a little bit how this answer will solve the problem, instead of posting code-only answer.
  • Talha Rasool
    Talha Rasool over 4 years
    Yeah sure @ArunVinoth In the IOS 13 the dark mode is introduced so if your deployment target is lower than 13 the use the above code else you can use simple statement written in if block.
  • Andrew___Pls_Support_UA
    Andrew___Pls_Support_UA over 4 years
    doesn't work for Xcode Version 11.3.1 (11C504) for some reason
  • Andrew___Pls_Support_UA
    Andrew___Pls_Support_UA over 4 years
    I have tried to set "LIGHT", "Light", "light", ".light", "1" -- all is the same - it doesn't work. Xcode: Version 11.3.1 (11C504)
  • Nico Haase
    Nico Haase about 4 years
    Please add some explanation to your answer by editing it, such that others can learn from it
  • sarah
    sarah over 3 years
    a little bit typo, it should be Appearance :)
  • alvin
    alvin over 3 years
    @Yodagama please check your simulator iOS version and Xcode version. It should work fine, I have just tested it in my simulator.
  • alvin
    alvin over 3 years
    It works fine in Xcode 12.3 and iOS 14.3. For your version, try the following <key>UIUserInterfaceStyle</key> <string>Light</string>
  • huync
    huync over 3 years
    The key in Info.plist has changed to Appearance. <key> Appearance</key> <string>Light</string>
  • Amit Khetan
    Amit Khetan about 3 years
    In newer versions, Info.plist add Appearance: Light/Dark
  • CSchwarz
    CSchwarz about 3 years
    In XCode 12.4 it showed as "Appearance" rather than User Interface Style.