我的应用程序的很大一部分由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'),
),
其他回答
if #available(iOS 13.0, *) {
overrideUserInterfaceStyle = .light
} else {
// Fallback on earlier versions
}
如果你没有使用Xcode 11或更高版本(即iOS 13或更高版本的SDK),你的应用程序没有自动选择支持暗模式。所以,没有必要选择退出黑暗模式。
如果你使用的是Xcode 11或更高版本,系统会自动为你的应用启用暗模式。根据你的喜好,有两种方法来禁用暗模式。你可以完全禁用它,也可以为任何特定的窗口、视图或视图控制器禁用它。
禁用黑暗模式完全为您的应用程序
你可以通过在你的应用的信息中包含一个值为Light的UIUserInterfaceStyle键来禁用暗模式。plist文件。 这忽略了用户的偏好,总是应用浅色外观的应用程序。
禁用窗口、视图或视图控制器的暗模式
通过设置适当窗口、视图或视图控制器的overrideUserInterfaceStyle属性,可以强制界面始终以浅色或深色样式显示。
视图控制器:
override func viewDidLoad() {
super.viewDidLoad()
/* view controller’s views and child view controllers
always adopt a light interface style. */
overrideUserInterfaceStyle = .light
}
视图:
// The view and all of its subviews always adopt light style.
youView.overrideUserInterfaceStyle = .light
亮点:
/* Everything in the window adopts the style,
including the root view controller and all presentation controllers that
display content in that window.*/
window.overrideUserInterfaceStyle = .light
注意:苹果强烈鼓励在你的应用中支持暗模式。 你只能暂时禁用黑暗模式。
阅读更多:为你的iOS应用程序选择特定的界面风格
斯威夫特5
您可以通过以下链接下载演示项目:- https://github.com/rashidlatif55/DarkLightMode
两种方法切换暗到亮模式:
1- info.plist
<key>UIUserInterfaceStyle</key>
<string>Light</string>
2-程序化或运行时
@IBAction private func switchToDark(_ sender: UIButton){
UIApplication.shared.windows.first?.overrideUserInterfaceStyle = .dark
}
只需在info中添加这些行。plist文件:
<key>UIUserInterfaceStyle</key>
<string>light</string>
这将迫使应用程序只在轻模式下运行。
我想我找到解决办法了。我最初从UIUserInterfaceStyle -信息属性列表和UIUserInterfaceStyle - UIKit拼凑在一起,但现在发现它实际上记录在为你的iOS应用程序选择特定的界面风格。
在你的信息里。将UIUserInterfaceStyle (User InterfaceStyle)设置为1 (UIUserInterfaceStyle.light)。
编辑:根据dorbeetle的回答,uiuserinterfacstyle更合适的设置可能是Light。