我的应用程序的很大一部分由web视图组成,以提供尚未通过本机实现提供的功能。网络团队没有计划为网站实施黑暗主题。因此,我的应用程序在iOS 13上的暗模式支持看起来会有点一半一半。
是否可以选择退出暗模式支持,这样我们的应用程序总是显示光模式,以匹配网站主题?
我的应用程序的很大一部分由web视图组成,以提供尚未通过本机实现提供的功能。网络团队没有计划为网站实施黑暗主题。因此,我的应用程序在iOS 13上的暗模式支持看起来会有点一半一半。
是否可以选择退出暗模式支持,这样我们的应用程序总是显示光模式,以匹配网站主题?
当前回答
只需简单地添加以下关键在您的信息。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
如果你想退出整个应用程序,上面的答案是有效的。如果你在有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"];
}
}
我的应用程序不支持黑暗模式,现在使用一个浅的应用程序栏颜色。我可以通过在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'),
),
我将使用这个解决方案,因为窗口属性可能会在应用程序生命周期中发生变化。因此需要重复分配" overrideuserinterfacstyle = .light"。UIWindow.appearance()使我们能够为新创建的UIWindow对象设置默认值。
import UIKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
if #available(iOS 13.0, *) {
UIWindow.appearance().overrideUserInterfaceStyle = .light
}
return true
}
}
是的. .你可以在iOS项目中添加以下设置。
在信息。将uiuserinterfacstyle添加到Light中。
如果你的项目在IONIC..您可以在配置文件中添加以下设置
<platform name="ios">
<edit-config file="*-Info.plist" mode="merge" target="UIUserInterfaceStyle">
<string>Light</string>
</edit-config>
</platform>
使用这些设置,设备暗模式不会影响你的应用程序。