113
votes

I'm creating an application and I want the status bar hidden. When I test the app, the status bar is hidden whilst the splash screen is shown, but once the app is fully loaded, the status bar reappears.

I'm using Xcode 5 and iOS 7, and have tried disabling the status bar programatically

  ([[UIApplication sharedApplication] setStatusBarHidden:YES    
      withAnimation:UIStatusBarAnimationFade];),

in the info.plist file, and using the attributes inspector on the .xib file. Nothing appears to work.

Any ideas?

14

14 Answers

221
votes

Try adding the following method to your app's root view controller:

- (BOOL)prefersStatusBarHidden
{
    return YES;
}
126
votes

You should add this value to plist: "View controller-based status bar appearance" and set it to "NO".

This will enable you to set the status bar to hidden mode. This sets it to a global unlike other provided answers.

UPDATE: If you want that the status bar would be hidden on splash screen don't forget to mark "Hide during application launch" on target status bar options. Also, you can add "Status bar is initially hidden" to "YES" on the plist if you don't want to do it with code inside the app.

73
votes

The code you posted works for iOS 6.1 and below. For iOS 7, Apple has made new methods available to directly control the status bar for each view. Turning off this option in your Info.plist will enable you to hide the status bar, at least for the current Developer Preview (4).

Add this and set to NO

For reference, please take a look at the iOS 7 transition guide that's available on Apple's developer portal.

36
votes

well I try hide the status bar in all my app and in the "app"-info.plist and I add two rows in the dictionary "Information Property List" I add "View controller-based status bar appearance" set NO and in "Status bar is initially hidden"set YES and for me works n_n'

plist info

17
votes

However, if you use UIImagePicker, the status bar appears again.

In that case, you should hide the status bar as below,

- (void)imagePickerController:(UIImagePickerController *)aPicker didFinishPickingMediaWithInfo:(NSDictionary *)info {

// for iOS7
    if ([self respondsToSelector:@selector(setNeedsStatusBarAppearanceUpdate)]) {

        [[UIApplication sharedApplication] setStatusBarHidden:YES];
    }
8
votes

After some long searching, I finally found a very simple solution which also takes care of the UIImagePickerController problem.

As mentioned in the other answers, set your status bar hidden in your AppDelegate didFinishLaunching, and set the "View controller-based status bar appearance" to NO.

Then, in your AppDelegate:

- (void)application:(UIApplication *)application didChangeStatusBarFrame:(CGRect)oldStatusBarFrame
{
      [application setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone];
}

et voila - your Status Bar will remain hidden even when the UIImagePickerController is foremost.

This is better than 'rehiding' it every time you present a UIImagePickerController as it remains hidden throughout the app.

7
votes

To hide the status bar on a particular UIViewController, simply add this:

-(BOOL)prefersStatusBarHidden
{
    return YES;
}

Hope this helps !

5
votes

You can hide from the project summary. there is a checkbox hide during launch.

See the snapshot

enter image description here

4
votes

I found this solution for me. It works like a charm. Write this code on your viewcontroller which you wanted to use UIImagePickerController on.

- (void)viewWillDisappear:(BOOL)animated
{
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone];
}
- (void)viewWillAppear:(BOOL)animated
{
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone];
     }
3
votes

In addition to the answer from alones above, make sure to implement the imagePickerControllerDidCancel method and add the same code there too.

2
votes

I was having issues with UIImagePicker as well. Similar to Alones answer, my solution was the following. I added this line or code:

[[UIApplication sharedApplication] setStatusBarHidden:YES];

to this function:

- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated

I haven't tested this with iOS 6 or older but it works great in iOS 7.

2
votes

Swift Solution

just add this to your view controllers:

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

I am using Xcode 6, this solution works on iOS 7 and 8 for me:

First, Set the "View controller-based status bar appearance" to NO in plist file.

Second, in AppDelegate, add this:

- (void)application:(UIApplication *)application didChangeStatusBarFrame:(CGRect)oldStatusBarFrame
{
      [application setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone];
}
0
votes

My problem was that I used view controller containment. Only the top most view controller, which is embedded into a navigation controller for example, can hide or show the status bar.