61

I am unable to change the text colour in the status bar in iOS 7 SDK. Currently its black and i want it to be white for all my view controllers in a storyboard.

I have seen few questions on StackOverflow like THIS, THIS and THIS but they didn't of much help. Also may be due to the fact that i am unable to find UIViewControllerBasedStatusBarAppearance to YES in my plist file.

Can any one tell me the right way to set the status bar text colour to white for all view controllers in the storyboard? Thanks in advance!

Community
  • 1
  • 1
AJ112
  • 5,291
  • 7
  • 43
  • 60

4 Answers4

199

Let me give you a complete answer to your question. Changing the status bar text colour is very easy but its a little confusing in iOS 7 specially for newbies.

If you are trying to change the colour from black to white in StoryBoard by selecting the view controller and going to Simulated Metrics on the right side, it won't work and i don't know why. It should work by changing like this but any how.

Secondly, you won't find UIViewControllerBasedStatusBarAppearance property in your plist but by default its not there. You have to add it by yourself by clicking on the + button and then set it to NO.

ios 7 status bar text color

Lastly, you have to go to your AppDelegate.m file and add the following in didFinishLaunchingWithOptions method, add the following line:

[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];

This will change the colour to white for all your view controllers. Hope this helps!

KC.
  • 3,186
  • 1
  • 13
  • 6
  • 3
    KC., I've done as you wrote and everything works fine. But when I open for example camera roll in my app, it sets status bar text colour to black, and when I dismiss camera roll status bar in my app has black text. I tried to set colour by using -(UIStatusBarStyle)preferredStatusBarStyle in my view controllers. But for unknown reason it's not being called. And for now I haven't found solution. – Oleg Oct 04 '13 at 16:45
  • 3
    I have the same issue as Oleg. Seems apples image picker overrides the default when handling it this way and refuses to switch back when you're done with it. – MattCheetham Oct 07 '13 at 11:39
  • I see the same thing when I open image picker popover on iPad. It also messes with my view coordinates, assuming there is a navigation bar. The fix is just to reset everything after the popover closes. – user1055568 Oct 21 '13 at 23:15
  • 4
    Use this navigationbar delegate method in your viewcontroller which is presenting imagepicker- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated { [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent]; } } – SreeHarsha Nov 06 '13 at 11:05
  • 2
    I too see the same issue as @Oleg and @MattCheetham . When using the APple image picker, the status bar goes completely black and stays that way, even after the image picker is dismissed. The fixes listed here don't influence this, and neither does a category on UIViewController overriding -`(UIStatusBarStyle)preferredStatusBarStyle` – chadbag Nov 14 '13 at 00:29
  • Thanks, it's working now, except for the splash screen. How can one active it while the splash screen is loading? – Riaan de Lange Dec 27 '13 at 19:47
  • @KC just small comment on this - Simulated Metrics panel group in InterfaceBuilder is not dedicated for specifying properties of navigation/status/etc. bars at runtime. Instead - "Simulated" means that anything you change here will be simulated right in your xib/storyboard file, i.e. it relates only to the design of your interface, and does not affect how it will be presented during your app runtime. – peetonn Jan 13 '14 at 15:56
  • The reason it doesn't work in "Simulated Metrics" is because it is just that, "Simulated" for the purpose of viewing appearance in Interface Builder. It doesn't not change the actual property. – Micah Jan 21 '14 at 22:37
  • I was tryig and trying to make it work. Apparently label uses also navigation bar setting to set colour. !!! You can not see it if you set custom colour. So it will set light when navigation bar is dark (later NB can be overriden by custom color). – BlueConga Jan 25 '14 at 16:53
  • A further possible bug in IOS7 if you use UIImagePickerController. Attempt to choose any image in the camera roll and your status bar remains with the picker style until killed. – kasuku Mar 25 '14 at 15:09
  • There is another SO discussion on this: http://stackoverflow.com/questions/18880364/uiimagepickercontroller-breaks-status-bar-appearance – kasuku Mar 25 '14 at 15:22
  • Hi, in one of my controllers i have something like this in my code.. `self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:153/255.0f green:204/255.0f blue:102/255.0f alpha:1.0f];` This code also changes the color of my status bar. How can i prevent this? – eurica Jun 05 '14 at 08:49
  • Please read this link https://mythodeia.wordpress.com/2014/05/09/view-controller-based-status-bar-appearance/ – akhiljayaram Feb 20 '15 at 13:25
43

If you're looking for UIViewControllerBasedStatusBarAppearance, you'll need to click the little plus sign that appear when you hover over the root element in your plist file.

plist file

Once you do that, a new row will appear - select "View controller-based status bar appearance" from the dropdown list and set NO as its value. (That friendly name is declared internally as UIViewControllerBasedStatusBarAppearance)

Next, calling the following method in your app delegate should set the status bar color to white for all view controllers:

[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
AbdullahC
  • 6,420
  • 3
  • 24
  • 42
24

Set the UIViewControllerBasedStatusBarAppearance to YES in the plist

In viewDidLoad do a [self setNeedsStatusBarAppearanceUpdate];

Add the following method:

-(UIStatusBarStyle)preferredStatusBarStyle{ 
    return UIStatusBarStyleLightContent; 
}
Adrian P
  • 6,439
  • 4
  • 36
  • 55
Claudia Mardegan
  • 567
  • 4
  • 14
  • Weird the previous answers worked for me before. Anyway, Thanks! This worked for me. BTW if this only gets updated on viewdidload therefore I have to call this update every view? – Teffi Feb 10 '14 at 03:16
  • this worked for me, but KC's solution did not work as well as storyboard method didn't work – vp_gold Apr 20 '14 at 17:00
  • This is what works if you have screens of different lightness-es – stackOverFlew Oct 24 '15 at 21:33
16

It is YES by default, so you won't see it. You need to add

UIViewControllerBasedStatusBarAppearance

to your plist and set it to NO.

Then you can call

[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
sankalp
  • 495
  • 4
  • 14
Leo Natan
  • 55,734
  • 8
  • 140
  • 186
  • 'setStatusBarStyle:' is deprecated: first deprecated in iOS 9.0 - Use -[UIViewController preferredStatusBarStyle] – ilke.uygun Oct 05 '17 at 13:58