我们如何在iOS 9中为整个应用程序设置Status Bar的Light Content样式? [英] How we can set the Light Content style of Status Bar in iOS 9 for whole application?

查看:598
本文介绍了我们如何在iOS 9中为整个应用程序设置Status Bar的Light Content样式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



iOS 9中不推荐使用以下方法而不使用替换方法。


-setStatusBarStyle:animated:



设置状态栏的样式,可选择为过渡设置动画
新的风格。


正在 AppDelegate 中工作如下: / p>

Swift 1.2代码:

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

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

 <错误>:CGContextSaveGState:无效的上下文0x0。如果要查看回溯,请设置CG_CONTEXT_SHOW_BACKTRACE环境变量。 
<错误>:CGContextTranslateCTM:无效的上下文0x0。如果要查看回溯,请设置CG_CONTEXT_SHOW_BACKTRACE环境变量。
<错误>:CGContextRestoreGState:无效的上下文0x0。如果要查看回溯,请设置CG_CONTEXT_SHOW_BACKTRACE环境变量。

所以根据



我不想为每个设置Light Content每个视图。



任何su ggestions?



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

解决方案

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



这会自动将状态栏的样式转换为 .LightContent 因为这个UINavigationController在命令中。


I want to apply Light Content style to the whole application.

Following method is deprecated in iOS 9 without the replacement method.

-setStatusBarStyle:animated:

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

Is working in the AppDelegate like as :

Swift 1.2 Code :

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

But when I upgrade my project to iOS 9/Swift 2 they are giving me warning message about :

<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.

So as per the solution from the apple forum and from this answer CGContextSaveGState: invalid context 0x0 Error only on device

So, I have removed the property UIViewControllerBasedStatusBarAppearance from the info.plist file as per the solution.

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

From the forum :

I don't want to set the Light Content for each and every view.

Any suggestions?

Objective-C should have the same issue.

解决方案

You can save yourself a lot of work by using a UINavigationController and setting its navigation bar's barStyle to .Black. You only have to do this once; you can do it in the storyboard editor.

This will automatically turn your status bar's style to .LightContent as long as this UINavigationController is in command.

这篇关于我们如何在iOS 9中为整个应用程序设置Status Bar的Light Content样式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆