Hide Status Bar In iOS 8 app

Objective CIos8Statusbar

Objective C Problem Overview


I have tried

[[UIApplication sharedApplication] setStatusBarHidden:YES]; 

This does nothing.

And I have looked in my Info.plist file for "View controller-based status bar appearance" but it's not there.

How can I hide the white status bar at the top of the screen (with the clock and battery charge) inside my app for Xcode 6? Thank you!

Objective C Solutions


Solution 1 - Objective C

You need to override this method on each view controller unless you have that plist entry.

Objective-C

-(BOOL)prefersStatusBarHidden{
    return YES;
}

Swift 2

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

Swift 3+

override var prefersStatusBarHidden: Bool {
    return true
}

And don't forget to set (if you present a view controller by calling the presentViewController:animated:completion: method):

Objective-C

vcToBeShownWithoutStatusbar.modalPresentationCapturesStatusBarAppearance = YES;

Swift

vcToBeShownWithoutStatusbar.modalPresentationCapturesStatusBarAppearance = true

Documentation: https://developer.apple.com/reference/uikit/uiviewcontroller/1621453-modalpresentationcapturesstatusb

If you change status bar from some container view controller (eg. UINavigationController or UIViewController with child view controllers) and you would like to change view controller responsible for status bar you should use childViewControllerForStatusBarHidden: property. Eg:

Set first view controller instance always responsible for status bar management

Objective-C

- (UIViewController *)childViewControllerForStatusBarHidden {
    return childViewControllers.first; // or viewControllers.first
}

Swift 2

override var childViewControllerForStatusBarHidden() -> UIViewController? {
    return childViewControllers.first // or viewControllers.first
}

Swift 3+

override var childViewControllerForStatusBarHidden: UIViewController? {
    return childViewControllers.first // or viewControllers.first
}

Set container view controller responsible for status bar management

Objective-C

- (UIViewController *)childViewControllerForStatusBarHidden {
    return nil;
}

Swift 2

override func childViewControllerForStatusBarHidden() -> UIViewController? {
    return nil
}

Swift 3+

override var childViewControllerForStatusBarHidden: UIViewController? {
    return nil
}

Documentation: https://developer.apple.com/documentation/uikit/uiviewcontroller/1621451-childviewcontrollerforstatusbarh

Solution 2 - Objective C

  1. Go to Info.plist file
  2. Hover on one of those lines and a (+) and (-) button will show up.
  3. Click the plus button to add new key
  4. Type in start with capital V and automatically the first choice will be View controller-based status bar appearance. Add that as the KEY.
  5. Set the VALUE to "NO"
  6. Go to you AppDelegate.m for Objective-C (for swift language: AppDelegate.swift)
  7. Add the code, inside the method

For Objective-C:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    [application setStatusBarHidden:YES];
 
    return YES;
}

For Swift:

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey:Any]?) -> Bool {
    application.statusBarHidden = true

    return true
}

Done! Run your app and no more status bar!

Solution 3 - Objective C

You can hide the status bar without writing a single line of code, it just requires two entries into the info.plist the first is

"View controller-based status bar appearance" set to NO

the second is

"Status bar is initially hidden" set to YES

Solution 4 - Objective C

You can add that row to your Info.plist file if it isn't there. Just go to the project in Xcode, go to the "Info" section, and hover over one of the existing rows. A "+" button should appear, allowing you to add a line and input "View controller-based status bar appearance".

Solution 5 - Objective C

For iOS 10 with Swift 3 you should use:

override var prefersStatusBarHidden: Bool {
    get {
        return true
    }
}

Solution 6 - Objective C

  1. Open info.plist
  2. "View controller-based status bar appearance" set to NO
  3. "Status bar is initially hidden" set to YES
  4. Done

No need to write a line of code...Cheers

Solution 7 - Objective C

If you use UIDocumentInteractionController to show data then you never hide status bar so i have alternate of this

 [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];

this line change the color of status bar content into white

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAggressorView Question on Stackoverflow
Solution 1 - Objective CVaporwareWolfView Answer on Stackoverflow
Solution 2 - Objective CnycdanieView Answer on Stackoverflow
Solution 3 - Objective CCSJordanView Answer on Stackoverflow
Solution 4 - Objective CNerrolkenView Answer on Stackoverflow
Solution 5 - Objective CRamon VasconcelosView Answer on Stackoverflow
Solution 6 - Objective CemrazView Answer on Stackoverflow
Solution 7 - Objective CTesterView Answer on Stackoverflow