How to Opt-Out of Dark Mode on iOS 13

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

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)

Sample Image


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.

Opting out of Dark Mode with iOS 15 using Xcode 13

For anyone else who lands here using Xcode 13. Here are the steps

  1. First, click on your project.

Sample Image


  1. Click on "Info"

Sample Image


  1. Click on the "+" on any Key to open a new K,V pair and add "Apperance" -> set value to "Light"

Sample Image


  1. Double check it exists in "Build Settings" under Info.plist Values under "User Interface Style" -> Light

Sample Image

Why doesn't my iOS app disable dark mode?

Simply you can add a new key UIUserInterfaceStyle in your app info.plist (Notes: Xcode 12 and above has renamed to Appearance) and set its value to Light or Dark. this will override the app default style to the value you provide.

so you don't need to bother about having it anywhere else

How can I disable dark mode for all UIViewControllers without using Any BaseUIViewController?

You can 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.

How do I prevent iOS 13's Dark Mode from changing the text color in my app's status bar?

iOS 13 Solution(s)

UINavigationController is a subclass of UIViewController! (who knew )

Therefore, when presenting view controllers embedded in navigation controllers, you're not really presenting the embedded view controllers; you're presenting the navigation controllers! UINavigationController, as a subclass of UIViewController, inherits preferredStatusBarStyle and childForStatusBarStyle, which you can set as desired.

Any of the following methods should work:

  1. Opt out of Dark Mode entirely

    • In your info.plist, add the following property:
      • Key - UIUserInterfaceStyle (aka. "User Interface Style")
      • Value - Light
  2. Override preferredStatusBarStyle within UINavigationController

    • preferredStatusBarStyle (doc) - The preferred status bar style for the view controller

    • Subclass or extend UINavigationController

        class MyNavigationController: UINavigationController {
      override var preferredStatusBarStyle: UIStatusBarStyle {
      .lightContent
      }
      }

      OR

        extension UINavigationController {
      open override var preferredStatusBarStyle: UIStatusBarStyle {
      .lightContent
      }
      }

  3. Override childForStatusBarStyle within UINavigationController

    • childForStatusBarStyle (doc) - Called when the system needs the view controller to use for determining status bar style
    • According to Apple's documentation,

    "If your container view controller derives its status bar style from one of its child view controllers, [override this property] and return that child view controller. If you return nil or do not override this method, the status bar style for self is used. If the return value from this method changes, call the setNeedsStatusBarAppearanceUpdate() method."

    • In other words, if you don't implement solution 3 here, the system will fall back to solution 2 above.

    • Subclass or extend UINavigationController

        class MyNavigationController: UINavigationController {
      override var childForStatusBarStyle: UIViewController? {
      topViewController
      }
      }

      OR

        extension UINavigationController {    
      open override var childForStatusBarStyle: UIViewController? {
      topViewController
      }
      }

    • You can return any view controller you'd like above. I recommend one of the following:

      • topViewController (of UINavigationController) (doc) - The view controller at the top of the navigation stack
      • visibleViewController (of UINavigationController) (doc) - The view controller associated with the currently visible view in the navigation interface (hint: this can include "a view controller that was presented modally on top of the navigation controller itself")

Note: If you decide to subclass UINavigationController, remember to apply that class to your nav controllers through the identity inspector in IB.

Edits: Strikethrough edits were made to remove extensions as a suggested answer. Other developers noted that they stopped working in Xcode 11.4 and Apple's documentation discourages the use of this ambiguous behavior.

P.S. My code uses Swift 5.1 syntax /p>

how to Disable Dark mode in in my application

  • For entire App (Window):
window!.overrideUserInterfaceStyle = .light

You can get the window from SceneDelegate or any view.window

  • For a single ViewController:
viewController.overrideUserInterfaceStyle = .light

You can set any viewController, even inside the viewController itself

  • For a single View:
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.

How to force disable iOS dark mode in React Native

The solution is to either

  1. add this to your Info.plist file:
    <key>UIUserInterfaceStyle</key>
<string>Light</string>

OR


  1. Add this to your AppDelegate.m:
    if (@available(iOS 13.0, *)) {
rootView.overrideUserInterfaceStyle = UIUserInterfaceStyleLight;
}


Related Topics



Leave a reply



Submit