How to hide status bar of a single view controller in iOS 9?

后端 未结 15 1291
挽巷
挽巷 2020-12-13 06:15

In a ViewController, which I presented modally, I did this:

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

This used

15条回答
  •  余生分开走
    2020-12-13 06:54

    I'm using Xcode Version 9.2 / Swift 3.2 / iOS 11

    I got this answer form BADCloud although I'm not sure why it didn't work for him.

    Anyway it worked for me for a specific view controller.

    The difference between this answer and the other answers on here is that in my info.plist when I initially had View controller-based status bar appearance - NO with the 2 statusBar methods below it didn't work but when I changed it to Yes is worked with both of them.

    In the info.plist change: View controller-based status bar appearance - YES

    In the view controller you want it changed in add:

    override func viewDidLoad() {
            super.viewDidLoad()
    
            // add this in ViewDidLoad
            setNeedsStatusBarAppearanceUpdate()
    }
    
    // add this underneath ViewDidLoad
    override var prefersStatusBarHidden: Bool {
      return true
    }
    

提交回复
热议问题