5

I have read this questions, but not only this ones, without finding a solution to my problem:

What it actually happens to me is that I achieve to hide the content of the status bar, but no the status bar itself:

    override var prefersStatusBarHidden: Bool {

        return true

    }

It keeps appearing on the top of the screen, traslucid, with no content at all.

3 Answers 3

5

To hide the status bar programmatically in Swift 3:

UIApplication.shared.keyWindow?.windowLevel = UIWindowLevelStatusBar

To bring it back:

UIApplication.shared.keyWindow?.windowLevel = UIWindowLevelNormal 

If you want you can learn more about UIWindowLevel in Apple's docs.

0
1

Did you try setting the status bar options in General tab for your project?

check both "Hide status bar" and "Requires full screen"

enter image description here

0
1

Step 1: go into Info.plist and add a row called "View controller-based status bar appearance" and set its (boolean-only) value to "NO". This will give you control over the status bar instead of delegating it to UIKit.

Step 2: in the view controller that you want to hide the status bar in, in the viewDidLoad() function (the last function run after the view controller has loaded itself into memory), edit your status bar:

Swift 3, Xcode 8.3.3

To hide your status bar:

class YourViewController: UIViewController {

    // view did load
    override func viewDidLoad() {
        super.viewDidLoad()

        // custom status bar
        UIApplication.shared.isStatusBarHidden = false
        setNeedsStatusBarAppearanceUpdate()

    }

}

To change the color of your status bar:

class YourViewController: UIViewController {

    // view did load
    override func viewDidLoad() {
        super.viewDidLoad()

        // custom status bar
        UIApplication.shared.statusBarStyle = .lightContent //or .default
        setNeedsStatusBarAppearanceUpdate()

    }

}

Additionally, you can edit .statusBarFrame, .statusBarOrientation, and .statusBarOrientationAnimationDuration in this dot-syntax context.

Calling the setNeedsStatusBarAppearanceUpdate() method is recommended by Apple whenever a view controller's status bar attributes change.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.