74

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!

djromero
  • 19,551
  • 4
  • 71
  • 68
Aggressor
  • 13,323
  • 24
  • 103
  • 182
  • 4
    You can add entries to Info.plist as needed. Also, I suggest searching in SO and Google. This has been asked and answered a lot. You'll need to know how to search for answers to more complex issues soon, better start now. – djromero Oct 01 '14 at 16:36
  • 2
    Valid criticism, thank you. – Aggressor Oct 01 '14 at 16:39
  • 2
    Just a suggestion @djromero - if we stop users posting fresh versions of old questions the answers get old - shouldn't we encourage these? This also means the newcomers who answer these questions get credit and the whole system remains alive. – amergin Nov 24 '15 at 14:22
  • @amergin A duplicate question is not fresh in any sense. There are plenty of questions every day for newcomers. I don't remember exactly **1 year later**, but at that moment it was obvious that the question was already answered in SO. In fact the OP thanked me, so I don't know what's your point. – djromero Nov 26 '15 at 11:35
  • @djromero Please don't take my suggestion as a criticism. I needed an answer to this question and searched SO. I got numerous hits and looked for the more recent one. Older hits are quite often wrong as iOS changes over time. VaporwareWolf has 80 ups so far for his answer so the question/answer are obviously appreciated. – amergin Nov 26 '15 at 11:45
  • 1
    @amergin I don't take it as a criticism. I just want you to understand my point of view: a question can't be fresh, only different. Duplicate questions make it harder to search for them later. A suggestion or critic that you can make me: why didn't you vote to close it as dup? I don't remember. – djromero Nov 26 '15 at 11:54
  • it helped me, thanks – Trần Thị Diệu My Aug 07 '17 at 13:38

7 Answers7

173

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

Grubas
  • 602
  • 5
  • 13
VaporwareWolf
  • 10,143
  • 10
  • 54
  • 80
121
  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!

Slipp D. Thompson
  • 33,165
  • 3
  • 43
  • 43
nycdanie
  • 2,921
  • 3
  • 18
  • 21
  • 2
    Thank you, that's the first time I've found someone explain that well and it actually make sense – Karl Humphries May 02 '15 at 19:09
  • 7
    only first 5 steps are enough if you have added one more key to to info.plist , add this key = "Status bar is initially hidden" with value="Yes" – Mehul Thakkar Sep 10 '15 at 07:02
  • Thank you for !!!, just a small suggestion - you need not code in the appDelegate file, instead select the Hide status bar option in your XCode targets settings, plist changes still apply. Happy Coding !!! – Ashwin G Oct 19 '16 at 00:25
27

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

CSJordan
  • 461
  • 5
  • 6
11

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".

Nerrolken
  • 1,975
  • 3
  • 24
  • 53
9

For iOS 10 with Swift 3 you should use:

override var prefersStatusBarHidden: Bool {
    get {
        return true
    }
}
Ramon Vasconcelos
  • 1,466
  • 1
  • 21
  • 28
  • 1
    Indeed this works with iOS 10. I prefer the short version "override var prefersStatusBarHidden: Bool { return true }" – Calin Chitu Jan 14 '17 at 06:27
3
  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

emraz
  • 1,563
  • 20
  • 28
-4

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

Tester
  • 49
  • 3