2

I'm trying to change the font color of the status bar in one of my modal views to white. The other views are set to be white in the app delegate.

I've tried the following code found in an answer to a similar question in the ViewController.

 - (UIStatusBarStyle)preferredStatusBarStyle {

    return UIStatusBarStyleLightContent;
}

but that does not work since the font still appears as black.

Fairly new to the iOS scene, please help with any suggestions.

Undo
  • 25,204
  • 37
  • 102
  • 124
  • possible duplicate of [How to change Status Bar text color in iOS 7](http://stackoverflow.com/questions/17678881/how-to-change-status-bar-text-color-in-ios-7) – Jakub Mar 24 '14 at 14:53

2 Answers2

1

You need to use your current code in combination with setting the View controller-based status bar appearance key in Info.plist to YES.

The missing piece of the puzzle here, though, is that you also need to tell iOS that you want a status bar update with this:

- (void)setNeedsStatusBarAppearanceUpdate;

It's a method on UIViewController. Call it in viewDidLoad like this:

- (void)viewDidLoad
{
    [self setNeedsStatusBarAppearanceUpdate];
    ...

Note that it only works on iOS 7 and throws an exception on iOS 6 and below, so in all my projects I have a #define like this:

#define kIs7 ([[[UIDevice currentDevice] systemVersion] compare:@"7.0" options:NSNumericSearch] != NSOrderedAscending)

Then it's really simple to not run iOS 7-only methods on iOS 6 and below:

if (kIs7) [self setNeedsStatusBarAppearanceUpdate];
Undo
  • 25,204
  • 37
  • 102
  • 124
  • Thanks I was missing the plist info. I've input the code into my view controller.m file but....still comes out black. In the story board does my view, does my custom class have to be the name of the view controller? If it does I try to fill that out but I don't think it recognizes the file because it doesn't auto fill in the name. – user3272982 Feb 06 '14 at 18:50
  • I got! So everything can actually be solved in the plist. View Controller-based status actually has to be set to "NO" and another key needs to be added called "Status bar style" then set to Opaque Black. This will set all the view controllers to be consistently white. – user3272982 Feb 08 '14 at 21:30
0

That is how you change the status bar color to white. If it's not working, then you probably haven't enabled view controller based status bar appearance in your Info.plist.

Make sure you add the following key, and set its value to YES

View controller-based status bar appearance
Mick MacCallum
  • 124,539
  • 40
  • 277
  • 276