我正在用最新版本的Xcode构建一个iOS应用程序。
如果我设置
overrideUserInterfaceStyle = .light
到一个视图控制器,它会被设置为亮模式,如果暗模式被启用。
但是如果我把这段代码像这样放到AppDelegate中:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
window?.overrideUserInterfaceStyle = .light
return true
}
它不工作。
没有错误。根据设备所处的模式,应用程序只是处于亮模式或暗模式。
为什么overrideUserInterfaceStyle
不能在AppDelegate中工作?是因为我在应用中使用了标签栏控制器吗?我不这么认为。
在AppDelegate中调用overrideUserInterfaceStyle
太早了,窗口还没有创建。您可以使用SceneDelegatewillConnectTo
函数