113

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?

rmaddy
  • 314,917
  • 42
  • 532
  • 579
user2397282
  • 3,798
  • 15
  • 48
  • 94

14 Answers14

220

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

- (BOOL)prefersStatusBarHidden
{
    return YES;
}
Quentin
  • 3,971
  • 2
  • 26
  • 29
  • 2
    How to do this globally? – jjxtra Aug 25 '13 at 19:44
  • 16
    Also, as stated in the Apple docs, you should call the `[self setNeedsStatusBarAppearanceUpdate];` after calling this method with something other than the default value (the default value is NO). – manderson Sep 12 '13 at 13:51
  • 3
    @PsychoDad Check my answer for a more global solution. – Idan Sep 19 '13 at 23:59
  • 2
    Perfect, thank you. I just can't figure out why iOS 7 is doing this and not respecting XIBs that contain NO status bar settings! – justinhartman Sep 24 '13 at 08:51
  • 1
    Adding this on a ViewController added to the stack is all I needed to hide the statusbar in that viewcontroller; the statusbar returns when this viewcontroller is removed. – MacD Oct 02 '13 at 09:52
  • WHERE do you call setNeedsStatusBarAppearanceUpdate ?!! Inside prefersStatusBarHidden?? (It seems to work even if you don't call setNeedsStatusBarAppearanceUpdate.) – Fattie Feb 28 '14 at 14:44
  • 1
    @joeBlow I think what manderson is saying is that if you change the return value of the prefersStatusBarHidden method (like if you have more complicated logic than just 'return YES;') you'll need to call setNeedsStatusBarAppearanceUpdate to force iOS to call your prefersStatusBarHidden again. – Quentin Mar 03 '14 at 20:55
  • BTW for anyone reading, this is the only solid solution I've found iOS7, http://stackoverflow.com/a/19200027/294884 !! – Fattie Mar 03 '14 at 21:03
125

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.

cmd
  • 11,622
  • 7
  • 51
  • 61
Idan
  • 9,880
  • 10
  • 47
  • 76
  • 2
    Took me a lot of time to figure this out. It is a problem I think everyone would have and Apple didn't mention it enough. glad to help... – Idan Sep 20 '13 at 09:55
  • 7
    works fine, do not forget to set .plist value for "Status bar is initially hidden" to YES. – andreas-supersmart Sep 23 '13 at 14:21
  • 1
    Wow, that was the only thing that worked with Kobold2d 2.1.0 and iOS 7, thanks very much! – Binarian Sep 24 '13 at 11:25
  • What if you do want this plist value to be YES but hide the status bar for just 1 or 2 UIViewControllers? – mayuur Sep 24 '13 at 15:51
  • 5
    Apple are not really champions of backward compatibility. Let's all dance to their flute and update every single one of our apps. Sorry, venting frustration. Caused by Apple. – Henrik Erlandsson Sep 26 '13 at 13:41
  • I noticed that the solution worked for all simulators except iPhone Retina 4-inch 64-bit iOS 7.0, where the status bar appeared overlayed on the splash screen. I had to additionally set "Status bar is initially hidden" to YES. – kzia Sep 27 '13 at 15:10
  • @kzia This is true also to regular iPhone. but it's not so relevant to the case. I'll add that any case. thanks – Idan Sep 27 '13 at 19:25
  • 1
    finally it works for me. Because -(BOOL)prefersstatusbarhidden method not working in modelview. – utkal patel Oct 17 '13 at 13:27
  • You should really avoid using this deprecated approach to appearance management. Instead, learn how view controllers can control the appearance of the status bar. – lhunath Jan 14 '14 at 17:06
  • @Ihunath How (without building all the app from scratch)? – Idan Jan 15 '14 at 09:20
  • 1
    This is the correct answer... because I want to appear and disappear the bar from time to time and "prefersStatusBarHidden" method is permanent – user2387149 Jan 22 '14 at 18:25
  • @user2387149 True, but you could also return "NO" in some cases (should be really careful there). – Idan Mar 01 '14 at 10:15
  • 1
    It worked for me, thanks Idan // to show in specific view controller UIApplication.shared.isStatusBarHidden = false // to hide in specific view controller UIApplication.shared.isStatusBarHidden = true – Mohan Jun 30 '17 at 12:07
73

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.

Sven
  • 1,326
  • 10
  • 12
  • 3
    In my opinion, this answer is better because in my app, I only want to hide status bar in landscape mode, thanks! – Son Nguyen Aug 07 '13 at 03:11
  • thanks this helps me since i want to hide it for my entire app – kevinl Aug 20 '13 at 18:02
  • 2
    In my opinion, this answer should be the best answer -> It is explained here https://developer.apple.com/library/prerelease/ios/documentation/UserExperience/Conceptual/TransitionGuide/Bars.html#//apple_ref/doc/uid/TP40013174-CH8-SW1 – marceloquinta Sep 10 '13 at 14:57
  • 5
    I've done this, but it looks like it has just hidden the status bar, however, my app is still 'pushed down' by the amount of space the status bar would take up, and I can still see the battery indicator! – vedran Sep 11 '13 at 13:24
35

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

user_Dennis_Mostajo
  • 2,279
  • 4
  • 28
  • 38
  • 2
    This forces your app into a compatibility mode designed solely to make old apps run as intended on iOS 7 when developers have no time to fix the app for the new way to do things. Instead, you need to implement the prefer* methods in your view controllers. – lhunath Jan 14 '14 at 19:27
17

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];
    }
alones
  • 2,848
  • 2
  • 27
  • 30
  • 2
    I'm having the same issue. The status bar is hidden until I use UIImagePicker. I tried your solution and it isn't working for me. Did I need to add anything besides the code in your post? – Dev01 Sep 19 '13 at 21:09
  • @WootWoot I also added - (BOOL)prefersStatusBarHidden { return YES; } to view controllers. Please try it. – alones Sep 24 '13 at 14:18
  • doesn't seem to work for me.. should you actually call `setNeedsStatusBarAppearanceUpdate`? – RyanM Sep 30 '13 at 01:50
  • I need to hide status bar on a button click. I have tried below code but it didn't worked. Can some one please help me. [[UIApplication sharedApplication] setStatusBarHidden:YES]; – janitheshan Sep 30 '13 at 09:56
7

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.

ikuramedia
  • 6,038
  • 3
  • 28
  • 31
  • 2
    Although something still seems broken in iOS7 on iPad at least - the UIImagePickerController still throws up a status bar the second time it's shown... Hurrrr... :-( Currently I'm using the appDelegate along with hiding it again in every viewWillAppear. So even if it looks dirty for a short while it gets fixed again quickly. – ikuramedia Sep 26 '13 at 12:10
  • 1
    This is the only method that worked for me on iOS8... somehow prefersStatusBarHidden doesn't get called on my view controller. – mojuba May 17 '15 at 18:53
7

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

-(BOOL)prefersStatusBarHidden
{
    return YES;
}

Hope this helps !

Mike Gledhill
  • 27,846
  • 7
  • 149
  • 159
  • !! This is the solution that worked for me in iOS 9.2, modifying the plist had no effect. – mico Feb 19 '16 at 18:34
5

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

See the snapshot

enter image description here

sohail.hussain.dyn
  • 1,411
  • 1
  • 16
  • 26
4

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];
     }
xevser
  • 369
  • 4
  • 5
3

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

Swindler
  • 802
  • 10
  • 9
2

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.

Arn Gao
  • 3
  • 1
Dev01
  • 13,292
  • 19
  • 70
  • 124
  • 'setStatusBarHidden:' is deprecated: first deprecated in iOS 9.0 - Use -[UIViewController prefersStatusBarHidden] – snibbe Aug 23 '20 at 23:52
2

Swift Solution

just add this to your view controllers:

override func prefersStatusBarHidden() -> Bool {
    return true
}
Dan Beaulieu
  • 19,406
  • 19
  • 101
  • 135
0

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];
}
RRN
  • 1,127
  • 1
  • 12
  • 37
0

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.

testing
  • 19,681
  • 50
  • 236
  • 417