Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift 3 - how to hide Status Bar when using Over Full Screen

I'm developing a swift app and I can't find how to hide Status Bar when I use Over Full Screen presentation on my modal.

However, I put this line of code in my Modal View Controller :

override var prefersStatusBarHidden: Bool {
    return true
}

And it is working if I create a segue which is not a modal, or if I create a segue which is a modal but not with Over Full Screen presentation.

I searched on internet how to fix it, and I found people who had the same problem but there had no solution.

Also, I can't change the color of my Status Bar when I'm using Over Full Screen option. I don't understand why? I think it's related.

Thanks for your help!

like image 864
Marcus Avatar asked Mar 29 '17 08:03

Marcus


People also ask

How do I hide status bar in SwiftUI?

Make sure your initial SwiftUI View is a Navigation view where you hide the status bar. Then if you navigate to a tab bar view or any subsequent views the status bar will be hidden.

How do you hide the status bar on ios 14?

To completely hide it on the home screen, open up an app, such as Settings, and wait about three to four seconds. Press the home button again, and the status bar will be completely gone.


1 Answers

To hide the status bar when doing an over full screen modal, you need to set this in viewDidLoad:

override func viewDidLoad() {
    super.viewDidLoad()    
    modalPresentationCapturesStatusBarAppearance = true
}

Then do the standard method to hide the status bar:

override var prefersStatusBarHidden: Bool {
    return true
}
like image 151
bnussey Avatar answered Oct 16 '22 11:10

bnussey