StatusBarStyle 在 iOS 9 上未按预期工作

StatusBarStyle not working as expected on iOS 9

我正在尝试在我的 swift 应用程序上获得以下 StatusBarStyle :

我的 AppDelegate 使用 UINavigationController 如下

self.nav = UINavigationController(rootViewController: controller!)

所以我尝试将 UIBarStyle 设置为黑色,如下所示:

    self.nav?.navigationBar.barStyle = UIBarStyle.Black

但是,这会导致以下结果:

顺便说一句,在我的 Info.plist 上,我有以下设置

<key>UIStatusBarStyle</key>
<string>UIStatusBarStyleDefault</string>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>

这些设置会在 LaunchScreen 上产生所需的状态栏样式,但不会在其他屏幕上产生。

我什至尝试将以下方法添加到 UINavigationController 中的所有 VC

override func preferredStatusBarStyle() -> UIStatusBarStyle {
    return UIStatusBarStyle.Default
}

但这会导致以下状态栏样式:

在 iOS 9 上有 UINavigationController 的情况下,获得所需状态栏样式的最佳方法是什么?

此外,如果我删除 plist 条目并设置

 self.nav?.navigationBar.barStyle = UIBarStyle.Black 

在 AppDelegate 中,我得到以下结果:

此外,我删除了所有设置背景颜色的地方,除了 AppDelegate 中的以下位置(colorOne 是我想要在状态栏上显示的深蓝色)

self.window?.backgroundColor = colorOne

当我这样做时,我在状态栏上看到了浅蓝色,这是最接近我在此处看到的状态栏上需要的深蓝色的颜色

在 appDelegate 中使用:

  UINavigationBar.appearance().barTintColor = UIColor.redColor()
  UINavigationBar.appearance().translucent = false

显然你可以使用任何你想要的 UIColor...

希望对您有所帮助..

如果您需要特定的颜色,使用 RGB 的方式是最佳选择:

  UINavigationBar.appearance().barTintColor = UIColor(red: 5.0, green: 8.0, blue: 9.0, alpha:0.5) 

如果它不起作用,请尝试以下操作: var navigationBarAppearace = UINavigationBar.appearance()

    navigationBarAppearace.tintColor = UIColor.whiteColor()
    navigationBarAppearace.barTintColor = UIColor(red:15/255.0, green:  167/255.0, blue: 216/255.0, alpha: 1.0)