iOS 9 如何为整个应用程序设置 Status Bar 的 Light Content 样式?

How we can set the Light Content style of Status Bar in iOS 9 for whole application?

我想将 Light Content 样式应用于整个应用程序。

以下方法在 iOS 9 中已弃用,没有替换方法。

-setStatusBarStyle:animated:

Sets the style of the status bar, optionally animating the transition to the new style.

正在 AppDelegate 工作,如 :

Swift 1.2代码:

UIApplication.sharedApplication().setStatusBarStyle(UIStatusBarStyle.LightContent, animated: true)

但是当我将我的项目升级到 iOS 9/Swift 2 时,他们给我警告信息:

<Error>: CGContextSaveGState: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
<Error>: CGContextTranslateCTM: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
<Error>: CGContextRestoreGState: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.

因此根据 apple forum and from this answer

中的解决方案

所以,我已经按照解决方案从 info.plist 文件中删除了 属性 UIViewControllerBasedStatusBarAppearance

现在的情况是我们如何在iOS 9 中为整个应用程序设置状态栏的Light Content 样式?

来自论坛:

我不想为每个视图设置灯光内容。

有什么建议吗?

Objective-C 应该有同样的问题。

您可以通过使用 UINavigationController 并将其导航栏的 barStyle 设置为 .Black 来节省大量工作。您只需要做一次;你可以在故事板编辑器中完成。

只要此 UINavigationController 在命令中,这就会自动将您的状态栏样式变为 .LightContent

您还可以使用: UIApplication.shared.statusBarStyle = .lightContent。它也适用于 swift3.