2
votes

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.

2

2 Answers

1
votes

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];
0
votes

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