Search code examples
iosswiftstatusbar

set status bar?


How to hide, show or change the status bar dynamically on events such as click or value change?

I've googled for a well, but all I get is changed from the beginning as this. Here I need to do it dynamically.


Solution

  • Well for this you can do following based on events:

    //For hiding/unhiding:
        func hideStatusBar(shouldHide:Bool){
         UIApplication.shared.isStatusBarHidden = shouldHide
        }
    
        //For Light Style:
        func lightStatusBar(){
            UIApplication.shared.statusBarStyle = .lightContent
        }
    
        //For Standard Style:
        func standardStatusBar(){
            UIApplication.shared.statusBarStyle = .default
    
        }
    

    or you can tweak prefersStatusBarHidden: as well.