我的应用程序的很大一部分由web视图组成,以提供尚未通过本机实现提供的功能。网络团队没有计划为网站实施黑暗主题。因此,我的应用程序在iOS 13上的暗模式支持看起来会有点一半一半。

是否可以选择退出暗模式支持,这样我们的应用程序总是显示光模式,以匹配网站主题?


当前回答

是的,你可以跳过添加以下代码在viewDidLoad:

if #available(iOS 13.0, *) {
        // Always adopt a light interface style.
        overrideUserInterfaceStyle = .light
    }

其他回答

只需简单地添加以下关键在您的信息。Plist文件:

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

如果你想退出整个应用程序,上面的答案是有效的。如果你在有UI的库上工作,并且你没有编辑.plist的奢侈,你也可以通过代码来做。

如果你正在编译iOS 13 SDK,你可以简单地使用以下代码:

迅速:

if #available(iOS 13.0, *) {
    self.overrideUserInterfaceStyle = .light
}

Obj - c:

if (@available(iOS 13.0, *)) {
    self.overrideUserInterfaceStyle = UIUserInterfaceStyleLight;
}

然而,如果你希望你的代码也能在iOS 12 SDK(目前仍然是最新的稳定SDK)上编译,你应该使用选择器。使用选择器的代码:

Swift (XCode将显示此代码的警告,但这是目前唯一的方法,因为属性不存在于SDK 12,因此不会编译):

if #available(iOS 13.0, *) {
    if self.responds(to: Selector("overrideUserInterfaceStyle")) {
        self.setValue(UIUserInterfaceStyle.light.rawValue, forKey: "overrideUserInterfaceStyle")
    }
}

Obj - c:

if (@available(iOS 13.0, *)) {
    if ([self respondsToSelector:NSSelectorFromString(@"overrideUserInterfaceStyle")]) {
        [self setValue:@(UIUserInterfaceStyleLight) forKey:@"overrideUserInterfaceStyle"];
    }
}

这个问题有很多答案,而不是在信息中使用它。plist你可以在AppDelegate中这样设置:

#if compiler(>=5.1)
        if #available(iOS 13.0, *) {
            self.window?.overrideUserInterfaceStyle = .light
        }
        #endif

在Xcode 11.3和iOS 13.3上测试

你可以这样做:添加这个新键uiuserinterfacstyle到Info。plist,并将其值设置为Light。并检查警报控制器出现轻模式。

UIUserInterfaceStyle 光 如果你在你的整个应用程序中强制亮/暗模式,而不管用户的设置,通过添加关键uiuserinterfacstyle到你的信息。plist文件并将其值设置为Light或Dark。

是的,你可以跳过添加以下代码在viewDidLoad:

if #available(iOS 13.0, *) {
        // Always adopt a light interface style.
        overrideUserInterfaceStyle = .light
    }