kAiN
kAiN

Reputation: 2773

prefersStatusBarHidden issue in iOS 13

Hi everyone I'm trying to hide my statusBar in a View Controller but it doesn't seem to work .. I used the function:


 override var prefersStatusBarHidden: Bool {
         return true
    }

I also set the View controller-based status bar appearance in the plist file to YES

My status bar doesn't want to hide ... where am I doing wrong?

Upvotes: 6

Views: 5139

Answers (3)

1215ccc
1215ccc

Reputation: 41

you kan look this,you should override childForStatusBarHidden and childForStatusBarStyle 。

class CCNavigationController: UINavigationController {
    override var childForStatusBarHidden: UIViewController? {
        return self.topViewController
    }
    
    override var childForStatusBarStyle: UIViewController? {
        return self.topViewController
    }
}

Upvotes: 0

Michael
Michael

Reputation: 303

It looks like you're trying to specifically hide the status bar in a single ViewController.

In order to do that, you need have the following in that ViewController

self.modalPresentationCapturesStatusBarAppearance = true

override var prefersStatusBarHidden: Bool {
      return true
}

I also added View controller-based status bar appearance in my .plist and set it to YES.

Tested on the latest iOS 13.

Upvotes: 11

an0
an0

Reputation: 17530

If the target view controller is embedded in another container view controller such as UINavigationController you need to subclass that container view controller and override its childForStatusBarHidden to return the target view controller.

Upvotes: 0

Related Questions