'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?



Solution 1:[1]

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.

Solution 2:[2]

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.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 bandejapaisa
Solution 2 an0