Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS 7 and later: set status bar style per view controller


I tried many ways to set the status bar style (default or lightcontent) but can't get it to work on a per view controller basis. I can set the status bar style for the whole app only.

Does anyone have a hint?

I tried UIViewControllerBasedStatusBarAppearance

and

-(UIStatusBarStyle)preferredStatusBarStyle{      return UIStatusBarStyleLightContent;  } 

but these methods don't work.

like image 852
Van Du Tran Avatar asked Sep 25 '13 19:09

Van Du Tran


People also ask

How do I change the default view controller?

Click on the View Controller corresponding to the view that you want to be the initial view. Open the Attributes Inspector. Select the "Is Initial View Controller" check box in the View Controller section.


2 Answers

Have you tried this?

  1. Set "View controller-based status bar appearance" (UIViewControllerBasedStatusBarAppearance) to YES in your Info.plist. (YES is the default, so you can also just leave this value out of your plist.)

  2. In your viewDidLoad method, call [self setNeedsStatusBarAppearanceUpdate].

  3. Implement preferredStatusBarStyle, returning the status bar style that you want for this view controller.

    - (UIStatusBarStyle) preferredStatusBarStyle {      return UIStatusBarStyleLightContent;  } 
like image 121
Greg Avatar answered Sep 21 '22 15:09

Greg


There is a catch here if your view controller is inside standalone UINavigationController and not a part of Storyboard based UINavigationController then above all methods fail. I came across this situation and then in order to set the status bar to light style i used following

[self.navigationController.navigationBar setBarStyle:UIBarStyleBlack]; 

This worked perfectly for me.

like image 31
vishal dharankar Avatar answered Sep 19 '22 15:09

vishal dharankar