5

I’m trying to change the Status Bar colour mid-run, i.e. not when a controller is loaded. I change the view’s background colour, so I need to change it from the black to white and vice versa.

I know that I can change it using preferredStatusBarStyle and the setting in the plist, but as far as I can see that’ll only set it on first launching the view controller. I’d like to change it, for instance, when I hit a button.

Can I do that?

Luke
  • 9,512
  • 15
  • 82
  • 146

2 Answers2

24
  • Go to your application Plist and add this as new row & set it as NO.

    View controller-based status bar appearance  NO
    

Add a bool to determine state of UIStatusBar colour & add a Toggle method

@property(nonatomic) BOOL black;


-(void)toggleStatuSBar:(id)sender{

    if(black) {
        [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent animated:YES];
        black = NO;

    }else {
        [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault animated:YES];
        black = YES;
    }
}

here is a Sample ScreenShot

  • When Menu is Closed, the colour is White.

    enter image description here

  • When Menu is Open The colour is Black

    enter image description here

Hope that helps.

Balram Tiwari
  • 5,657
  • 2
  • 23
  • 41
  • This way you can change viewController's StatusBar independently. – Balram Tiwari Feb 17 '14 at 11:31
  • This has been deprecated in iOS 9. Is overriding the UIViewController method the only way now? That isn't ideal. – IIllIIll Oct 13 '15 at 20:06
  • 2
    @Arcrammer : The Original Post was answered more than an year ago by me, when the API was well functioning. It would be better to edit the answer & add the new api code. – Balram Tiwari Oct 15 '15 at 07:15
2

As of Swift 3:

  1. Go to your application Plist and add this as new row & set it as NO.

View controller-based status bar appearance NO

2.

White: UIApplication.shared.statusBarStyle = .lightContent

Black: UIApplication.shared.statusBarStyle = .default

Daniel
  • 357
  • 2
  • 11