如何在React Native中强制禁用iOS暗黑模式

32

iOS 13新版本引入了一种可选的全局系统。 这会导致StatusBar显示浅色文字,可能在白色背景上变得难以阅读。 它还破坏了iOS Datetime选择器(请参见DatePickerIOSreact-native-modal-datetime-picker)。

5个回答

90
解决方案是要么:
  1. 将以下内容添加到您的 Info.plist 文件中:
    <key>UIUserInterfaceStyle</key>
    <string>Light</string>

或者

  1. 将以下内容添加到您的AppDelegate.m文件中:
    if (@available(iOS 13.0, *)) {
        rootView.overrideUserInterfaceStyle = UIUserInterfaceStyleLight;
    }

1
@Hazwin,那听起来不太可能。 - Maxim Zubarev
@MaximZubarev 我猜他指的是 https://dev59.com/oVMI5IYBdhLWcg3wS5rP#56546554 - dwn
@Hazwin,如果你使用的是更新版本的Xcode,那么这并不正确,而且可能会误导一些读者。我在应用商店中有多个应用程序使用了Info.plist中的UIUserInterfaceStyle ligth。 - Jero
1
@Jero 是的,我的错。我指的是 https://dev59.com/oVMI5IYBdhLWcg3wS5rP#56546554 - Haswin

3

在你的 app.json 文件中添加:

{
  "expo": {
     ...
     "ios": {
      "infoPlist": {
        "UIUserInterfaceStyle": "Light"
      }
    },
}

1

这对我有用。

  1. 将此内容添加到 Info.plist 文件中。
<key>UIUserInterfaceStyle</key>
<string>Light</string>
将以下代码添加到您的AppDelegate.m文件中:
  if (@available(iOS 13.0, *)) {
      rootView.backgroundColor = [UIColor systemBackgroundColor];
    self.window.overrideUserInterfaceStyle = UIUserInterfaceStyleLight;
  } else {
      rootView.backgroundColor = [UIColor whiteColor];
  }

0
将此内容添加到您的 Info.plist 文件中。
<key>UIUserInterfaceStyle</key>
    <string>Light</string>

把这段代码添加到您的AppDelegate.m文件中。
  rootView.backgroundColor = [UIColor whiteColor];

0

这个解决方案似乎是最好的。将其添加到您的AppDelagate.m中。

  self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
  UIViewController *rootViewController = [UIViewController new];
  rootViewController.view = rootView;
  self.window.rootViewController = rootViewController;
  [self.window makeKeyAndVisible];

  //add this here vv

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

  //add this here ^^




 return YES;

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接