为什么我的iOS应用程序不禁用黑暗模式? [英] Why doesn't my iOS app disable dark mode?

查看:388
本文介绍了为什么我的iOS应用程序不禁用黑暗模式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以...我尝试通过按照苹果文档的强制采用浅色模式来设置我的应用程序以禁用iOS 13深色模式,在模拟器中,所有尝试都可以正常工作,但是当我在真实设备上尝试时,没有任何反应,这是就像我从未更改过代码一样

So ... I've tried to set my app to disable iOS 13 dark mode by forcing light mode according apple documentation, in the emulator all attempts work fine, but when I try on the real device, nothing happens, it's like I've never changed my code

首次尝试

覆盖窗口,视图或视图控制器的界面样式

我试图将此代码示例放入viewDidLoad()

I tried to put this code sample in my viewDidLoad()

未更改

if #available(iOS 13.0, *) {
   overrideUserInterfaceStyle = .light
} else {
  // Fallback on earlier versions
}

第二次尝试

完全退出暗模式

系统会自动在与iOS 13.0或更高版本的SDK链接的任何应用中选择亮外观和暗外观.如果您需要更多时间来处理应用程序的暗模式"支持,可以通过在应用程序的Info.plist文件中包含UIUserInterfaceStyle键(值为Light)来暂时退出.将此键设置为"Light"会导致系统忽略用户的偏好,并始终为您的应用程序添加浅色外观.

The system automatically opts in any app linked against the iOS 13.0 or later SDK to both light and dark appearances. If you need extra time to work on your app's Dark Mode support, you can temporarily opt out by including the UIUserInterfaceStyle key (with a value of Light) in your app’s Info.plist file. Setting this key to Light causes the system to ignore the user's preference and always apply a light appearance to your app.

没什么改变

Apple文档:为iOS应用程序选择特定的界面样式

如果有人知道我如何只在灯光模式下设置我的应用程序,我将非常感激:D

If anyone knows how I set my app only in light mode... I'll be very grateful :D

推荐答案

您只需在应用程序 info.plist 中添加新密钥 UIUserInterfaceStyle 并设置其值 Light or Dark .这会将应用默认样式替换为您提供的值.

Simply you can add a new key UIUserInterfaceStyle in your app info.plist 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

这篇关于为什么我的iOS应用程序不禁用黑暗模式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆