Search code examples
iosswiftxcodeuiviewcontrolleruistatusbar

Hide status bar in all view controllers - IOS


If I want to hide the status bar of a single view controller subclass then I do this:

override var prefersStatusBarHidden: Bool {
    return true
}

But what if I want to hide status bar by default in all view controllers subclass or not? Checking "Hide status bar" in the project settings does nothing.

I'm trying to program UIPageViewController which contains many view controllers attached to it. It would be nice not having to subclass them all.


Solution

  • Go to your Info.plist file and add a new attribute:

    View Controller based status bar appearance and set it to NO.

    enter image description here

    Then go to App Delegate and replace your method to this:

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
            // Override point for customization after application launch.
    
            UIApplication.shared.isStatusBarHidden = true
            return true
        }