Choosing a Specific Interface Style for Your iOS App(选择明确的界面样式)

文章目录
  1. 1. Overview
  2. 2. Override the Interface Style for a Window, View, or View Controller重写界面样式
  3. 3. Override the Interface Style for Child View Controllers重写子控制器的样式
  4. 4. Opt Out of Dark Mode Entirely 全部退出黑夜模式
  5. 5. 参考

Adopt a specific interface style for your views, view controllers, or app when it is inappropriate to support both light and dark variants.

当你的APP不适合light、dark模式时,为你的view,controller选择一个明确的样式。

Overview

系统假设在ios13或者以后, app默认支持light、dark样式。在IOS中,你可以为window、view、controller指定明确的样式。也可以在plist中静止黑夜模式。

Override the Interface Style for a Window, View, or View Controller重写界面样式

1
2
3
4
5
6
override func viewDidLoad() {
super.viewDidLoad()

// Always adopt a light interface style.
overrideUserInterfaceStyle = .light
}

Override the Interface Style for Child View Controllers重写子控制器的样式

1
var overrideTraitCollection: UITraitCollection? { get set }

Opt Out of Dark Mode Entirely 全部退出黑夜模式

在plist中设置 UIUserInterfaceStyle的值为Light。

Supporting Dark Mode is strongly encouraged. Use the UIUserInterfaceStyle key to opt out only temporarily while you work on improvements to your app’s Dark Mode support.

参考

  1. Choosing a Specific Interface Style for Your iOS App