Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
413 views
in Technique[技术] by (71.8m points)

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

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 :

enter image description here

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

Any suggestions?

Objective-C should have the same issue.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...