Hide status bar even when warning is displayed

I hide my status bar on a specific viewControllerusing

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

It works very well until I show a warning on the screen. When a warning appears, a status bar appears, which I do not want. When the warning is disabled, the status bar is hidden again.

+4
source share
5 answers

Since UIAlertControllerit is now fully functional UIViewController, you must subclass it and add the same method to the new subclass. Then create your subclass instead of simple UIAlertController.

Unconfirmed, but this should do the trick.

+4

, UIAlertController UIViewController, prefersStatusBarHidden , .

.

Swift3:

final class MYAlertController : UIAlertController {
    override var prefersStatusBarHidden: Bool {
        get {
            return true
        }
    }
}
+3

CustomAlertController UIAlertController

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

, , CustomAlertController, .

+1

swift 2

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

swift 3

override var prefersStatusBarHidden: Bool {
    return true
}

:

let alertController = UIAlertController(title: "Error", message: "No internet connection", preferredStyle: .alert)

        let OKAction = UIAlertAction(title: "OK", style: .default) { (action:UIAlertAction) in
            print("OK button pressed");
        }

        alertController.addAction(OKAction)
        self.present(alertController, animated: true, completion:nil)

    }

, , :

https://github.com/k-sathireddy/AlertControllerSample

+1

modalPresentationCapturesStatusBarAppearanceset value false. Try to set it on truefor UIAlertControllerwho you are trying to create.

0
source

Source: https://habr.com/ru/post/1655928/


All Articles