Change iOS7 Status Bar Colour programmatically, mid-run?

一世执手 提交于 2019-12-19 03:13:34

问题


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?


回答1:


  • 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.

  • When Menu is Open The colour is Black

Hope that helps.




回答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



来源:https://stackoverflow.com/questions/21827349/change-ios7-status-bar-colour-programmatically-mid-run

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!