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

2020-01-23 15:19发布

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?

19条回答
Summer. ? 凉城
2楼-- · 2020-01-23 15:50

You can off dark mode in entire application xcode 11 or more

  1. Go Info.plish
  2. Add bellow like

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

Info.plist will be look like bellow..

enter image description here

查看更多
【Aperson】
3楼-- · 2020-01-23 15:51

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

<key>UIUserInterfaceStyle</key>
    <string>Light</string>
查看更多
来,给爷笑一个
4楼-- · 2020-01-23 15:52

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

查看更多
兄弟一词,经得起流年.
5楼-- · 2020-01-23 15:52

- For entire App (Window):

window!.overrideUserInterfaceStyle = .light

You can get the window from SceneDelegate

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

查看更多
smile是对你的礼貌
6楼-- · 2020-01-23 15:53

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

查看更多
狗以群分
7楼-- · 2020-01-23 15:56

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.

查看更多
登录 后发表回答