Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 546
Miguel Moreno Avatar asked Dec 09 '22 11:12

Miguel Moreno


1 Answers

Option 1:

1) if your app is View controller-based then you have to set it app.plist file like this:

 UIViewControllerBasedStatusBarAppearance=NO;

enter image description here

2) you have to set this method in each controller:

 -(UIStatusBarStyle)preferredStatusBarStyle
  {
      return UIStatusBarStyleLightContent;
  }

Option 2:

Write this single line in AppDelegate.m file in application didFinishLaunchingWithOptions: method

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

May be it will help.

like image 58
Dhaval Bhadania Avatar answered Dec 11 '22 09:12

Dhaval Bhadania