5

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!

Marcus
  • 53
  • 1
  • 6

2 Answers2

5

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
}
bnussey
  • 1,894
  • 1
  • 19
  • 34
0

We can override preferredStatusBarStyle from individual view controller as you have done correctly.

Along with this, insert a new key named “View controller-based status bar appearance” and set the value to NO in your info.plist. enter image description here

By disabling the “View controller-based status bar appearance”, you can set the status bar style by using the following code.

[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent]; //objective-c

Hence it should solve "I can't change the color of my Status Bar when I'm using Over Full Screen option"

byJeevan
  • 3,728
  • 3
  • 37
  • 60
  • 1
    This is not working for my View Controller which is a modal. I still have the black Status bar – Marcus Mar 29 '17 at 11:48