我的应用程序的很大一部分由web视图组成,以提供尚未通过本机实现提供的功能。网络团队没有计划为网站实施黑暗主题。因此,我的应用程序在iOS 13上的暗模式支持看起来会有点一半一半。
是否可以选择退出暗模式支持,这样我们的应用程序总是显示光模式,以匹配网站主题?
我的应用程序的很大一部分由web视图组成,以提供尚未通过本机实现提供的功能。网络团队没有计划为网站实施黑暗主题。因此,我的应用程序在iOS 13上的暗模式支持看起来会有点一半一半。
是否可以选择退出暗模式支持,这样我们的应用程序总是显示光模式,以匹配网站主题?
当前回答
我的应用程序不支持黑暗模式,现在使用一个浅的应用程序栏颜色。我可以通过在Info.plist中添加以下键来强制状态栏内容为深色文本和图标:
<key>UIStatusBarStyle</key>
<string>UIStatusBarStyleDarkContent</string>
<key>UIUserInterfaceStyle</key>
<string>Light</string>
<key>UIViewControllerBasedStatusBarAppearance</key>
<true/>
在这里找到其他可能的值:https://developer.apple.com/documentation/uikit/uistatusbarstyle
颤振的用户
不要忘记在Flutter应用程序栏上设置应用程序栏亮度属性,如下所示:
AppBar(
backgroundColor: Colors.grey[100],
brightness: Brightness.light, // <---------
title: const Text('Hi there'),
),
其他回答
将此添加到info.plist
<key>UIUserInterfaceStyle</key>
<string>Light</string>
对于整个应用程序:(在信息。plist文件):
<key>UIUserInterfaceStyle</key>
<string>Light</string>
窗口(通常是整个应用程序):
window!.overrideUserInterfaceStyle = .light
你可以从SceneDelegate中获取窗口
UIViewController:
viewController.overrideUserInterfaceStyle = .light
你可以设置任何viewController,甚至在viewController内部
UIView:
view.overrideUserInterfaceStyle = .light
你可以设置任何视图,甚至在视图内部
如果你支持早期的iOS版本,你可能需要使用if #available(iOS 13.0, *){…}。
SwiftUI View):
.preferredColorScheme(.light) <- This Modifier
or
.environment(\.colorScheme, .light) <- This Modifier
我的应用程序不支持黑暗模式,现在使用一个浅的应用程序栏颜色。我可以通过在Info.plist中添加以下键来强制状态栏内容为深色文本和图标:
<key>UIStatusBarStyle</key>
<string>UIStatusBarStyleDarkContent</string>
<key>UIUserInterfaceStyle</key>
<string>Light</string>
<key>UIViewControllerBasedStatusBarAppearance</key>
<true/>
在这里找到其他可能的值:https://developer.apple.com/documentation/uikit/uistatusbarstyle
颤振的用户
不要忘记在Flutter应用程序栏上设置应用程序栏亮度属性,如下所示:
AppBar(
backgroundColor: Colors.grey[100],
brightness: Brightness.light, // <---------
title: const Text('Hi there'),
),
只需在info中添加这些行。plist文件:
<key>UIUserInterfaceStyle</key>
<string>light</string>
这将迫使应用程序只在轻模式下运行。
如果你将添加UIUserInterfaceStyle键到plist文件中,苹果可能会拒绝发布构建,如这里所述:https://stackoverflow.com/a/56546554/7524146 无论如何,显式地告诉每个ViewController self是很烦人的。overrideuserinterfacstyle = .light。但是你可以在根窗口对象上使用这段代码:
if #available(iOS 13.0, *) {
if window.responds(to: Selector(("overrideUserInterfaceStyle"))) {
window.setValue(UIUserInterfaceStyle.light.rawValue, forKey: "overrideUserInterfaceStyle")
}
}
请注意,你不能在应用程序(application: didFinishLaunchingWithOptions:)中这样做,因为这个选择器在早期阶段不会响应true。但你可以以后再做。如果你在你的应用中使用自定义AppPresenter或AppRouter类,而不是在AppDelegate中自动启动UI,这非常简单。