Search code examples
iosswiftstatusbaruialertcontroller

Hide status bar even when an alert is presented


I am hiding my status bar on a specific viewController using

override func prefersStatusBarHidden() -> Bool {
    return true
}

It is working very nice until I present an alert on the screen. When alert is presented status bar appears again, Which I do not want. When alert is dismissed status bar is hidden again.


Solution

  • As UIAlertController is now a full-fledged UIViewController, you should be able to subclass it and add the same method to the new subclass. Then instanciate your subclass instead of a plain UIAlertController.

    Untested, but that should do the trick.