Search code examples
iosiphoneobjective-cstatusbar

UIApplication.statusBarStyle changes between viewWillAppear and viewDidAppear


Running an app in iOS7 initially designed for previous versions, a dark grey navigation bar tints the status bar whose text is black.

I'm trying to adapt it to the newest version, and I'm setting the UIApplication.statusBarStyle to UIStatusBarStyleLightContent like this:

[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent animated:YES];

This piece of code should change the status bar text colour to white but it doesn't. I put a watchpoint in the _statusBarRequestedStyle property of my UIApplication instance and I could see that this is set to 0 (UIStatusBarStyleDefault) by some call from UIApplicationMain between the execution of viewWillAppear and viewDidAppear methods.

I can't figure out what/why the status bar style is changed at this point and I would appreciate any advice if you have experienced the same.

Thanks in advance!

EDIT: From iOS 7 UI Transition Guide (https://developer.apple.com/library/ios/documentation/userexperience/conceptual/TransitionGuide/Bars.html)

In iOS 7, you can control the style of the status bar from an individual view controller and change it while the app runs. If you prefer to opt out of this behavior and set the status bar style by using the UIApplication statusBarStyle method, add the UIViewControllerBasedStatusBarAppearance key to an app’s Info.plist file and give it the value NO.


Solution

  • I think what happens is the system is updating the status bar according to the view controller status bar appearance. This is new behavior to iOS7, and is on by default.

    If you want to use the previous API for status bar appearance, you should set UIViewControllerBasedStatusBarAppearance to NO in your app's info.plist.