Change iOS7 Status Bar Colour programmatically, mid-run?

后端 未结 2 1704
抹茶落季
抹茶落季 2021-01-05 22:57

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 whi

相关标签:
2条回答
  • 2021-01-05 23:53
    • 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.

    0 讨论(0)
  • 2021-01-05 23:56

    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

    0 讨论(0)
提交回复
热议问题