3
votes

I have problems with colour of text in Status Bar. I want to make colour of text white, but keep black colour on modal views.

I have next configuration:

  • Storyboard with settings "Opens in 5.1" and "Project Deployment target 7.0" and "View as iOS7 and later"
  • UITabBarViewController
  • 4 UINavigationControllers
  • Each navigation controller has custom subclass of UIViewController inside

Background colour of UINavigationBar set to dark via appearance.

View controller-based status bar appearance set to YES

My subclass of UITabBarViewController has next methods:

- (UIStatusBarStyle)preferredStatusBarStyle {
    return UIStatusBarStyleLightContent;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setNeedsStatusBarAppearanceUpdate];
}

These methods are called after application started.

I also have same methods calls in my UIViewControllers subclasses:

- (UIStatusBarStyle)preferredStatusBarStyle {
    return UIStatusBarStyleLightContent; // This method never called
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setNeedsStatusBarAppearanceUpdate];
}

I also tried to change return value of -preferredStatusBarStyle to UIStatusBarStyleDefault (well, I know that it should paint text in black, but I tried anyway)

Same thing for setting Status Bar option to Light Content in Storyboard. Doesn't work too.

I know there are a lot of questions on SO similar to mine, but proposed solutions doesn't help in my situation.

My status bar still looks like this:

StatusBar

And I want to change its colour to white =/

3

3 Answers

4
votes

This is a work around that I occasionally found right now after struggling with this issue for about 2 weeks.

// This is a workaround just enables white text colour in status bar in iOS7, iOS7.1
// Dont touch it until things break
// Despite this category says "draw white", colour automatically becomes black on white background w/o additional code
@interface UINavigationController (StatusBarStyle)

@end

@implementation UINavigationController (StatusBarStyle)
- (UIStatusBarStyle)preferredStatusBarStyle {
    return UIStatusBarStyleLightContent;
}
@end
// Place at the bottom of your AppDelegate.m
// Magic!

I need to thank people who answered this question, but I already tried these solutions and they didn't help :( This category on UINavigationController just works.

2
votes

First of all, you say that - (UIStatusBarStyle)preferredStatusBarStyle is never called in your UIViewController subclasses. It's normal. This method is called by your root view controller. In your case, it is the UITabBarViewController.

You also say that you've tried to set Status Bar option to Light Content in Storyboard. If you look closely, you should have done that in a section named Simulated metrics. So as the title suggest, modifications here are simulated...

I suggest you to try to add the key UIViewControllerBasedStatusBarAppearance in your Info.plist and to set it to YES.

0
votes

You need to set this in your RootViewController :

[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];