270

I just upgraded my iPhone 5 iOS 7 to four beta version. Now when I run my app from Xcode 5 on this iPhone, status bar doesn’t hide, even though it should.

Not Working:

[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationFade];

Not Working:

[UIApplication sharedApplication].statusBarHidden = YES;

Can't login to Apple Developer Forums

Brian
  • 14,610
  • 7
  • 35
  • 43
Melih Büyükbayram
  • 3,100
  • 2
  • 17
  • 16
  • 15
    Untrue, my answer involved Xcode and that has been shown to the general public. It's too general to say 'if you answer this, it's a breach of NDA' .. let developers decide that for themselves ;-) – Jake Aug 05 '13 at 15:52
  • possible duplicate of [Status bar won't disappear](http://stackoverflow.com/questions/17763719/status-bar-wont-disappear) – ekhumoro Nov 11 '13 at 18:04
  • how to hide status bar programmatically particular ViewController ? – bhavik Sep 22 '14 at 07:47

26 Answers26

560

in your apps plist file add a row call it "View controller-based status bar appearance" and set it to NO

Note that this simply does not work, if you are using UIImagePickerController in the app.

from http://www.openfl.org/developer/forums/general-discussion/iphone-5ios-7-cant-hide-status-bar/, mgiroux's solution

An example adding View Base Controller to your Info settings in Xcode

Ian Jamieson
  • 4,376
  • 2
  • 35
  • 55
satgi
  • 6,353
  • 3
  • 18
  • 18
  • 12
    For reference, the raw value stored in the actual Info.plist file is called `UIViewControllerBasedStatusBarAppearance`. – Adam Rosenfield Oct 03 '13 at 18:07
  • I have had to apply in Custom iOS Target Properties, because in the general plist didn't work – xarly Oct 08 '13 at 16:32
  • 55
    The only problem with this approach is if you use the UIImagePickerController to select images it will force the status bar to appear once more.The only sure fire way to prevent this is to implement the prefersStatusBarHidden method in each of your view controllers and reset the UIViewControllerBasedStatusBarAppearance plist setting to be true. – Jason Fuerstenberg Oct 19 '13 at 00:16
  • 5
    I really don't know why Apple has changed this ! Thanks :) – Mohamed Amine Nov 05 '13 at 16:42
  • 19
    You also need to set `Status bar is initially hidden` to **YES**. – Zorayr Jan 02 '14 at 04:44
  • This doesn't work. If you add the Status bar is initially hidden: YES the app freezes up and won't run. – jdog Feb 19 '14 at 15:42
278

Add method in your view controller.

- (BOOL)prefersStatusBarHidden {
    return YES;
}
Stunner
  • 12,025
  • 12
  • 86
  • 145
invoodoo
  • 3,905
  • 1
  • 18
  • 16
  • 35
    For all those looking, this is the way to do it if you want to dynamically remove the status bar in certain views. This method works regardless of what you set "View controller-based status bar appearance" to in your plist! – Mr. T Sep 23 '13 at 04:19
  • 2
    +1 b/c I am looking for the ability to dynamically show/hide the status bar. P-list setting method (see post by @Satgi above) is however the best way to show/hide the status bar globally. – JonnyB Nov 06 '13 at 04:36
  • If you have a photo gallery somewhere you usually want to hide the controls only there, and you can turn it on/off as well. This does not work for me, the function is not even called. I have in the same place a preferredStatusBarStyle and is called – Cristi Băluță Nov 12 '13 at 17:11
  • Sorry, it actually works on a blank project, but is not working on mine for some reason. – Cristi Băluță Nov 12 '13 at 17:29
  • I also added this code to view controller not in blank project, and it works. What version of iOS do you test? This code works only for iOS7, if you're trying to hide in iOS6 it won't work. – invoodoo Nov 13 '13 at 09:47
  • Worked for me in an existing project for iOS6 and iOS7. – Phil_12d3 Nov 19 '13 at 11:17
  • this should be the correct answer as it solves the UIImagePickerController bug – d370urn3ur Mar 03 '14 at 15:29
  • 4
    @Mr.T In iOS 8, it seems no longer the case. If you have set view controller based status bar appearance to NO and return true from `prefersStatusBarHidden` in a view controller, it would not work. The status bar still appears. – Isuru Aug 15 '14 at 08:26
  • @Isuru Did you find a solution for iOS8? – hybridcattt Oct 01 '14 at 14:00
  • 1
    @Isuru why did you set to NO? If you set to YES it would ask every view controller in other case of course it wouldn't. – invoodoo Oct 02 '14 at 00:00
85

In the Plist add the following properties.

-> Status bar is initially hidden = YES

-> View controller-based status bar appearance = NO

Add both - now the status bar will disappear.

Stunner
  • 12,025
  • 12
  • 86
  • 145
user1179912
  • 871
  • 5
  • 6
  • Yep, this worked for me also. Without setting "Status bar is initially hidden" option to YES its not working as expected. Thx. – AndrewShmig Mar 15 '14 at 12:45
54

To hide Status Bar on a Single view, you should use:

[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationSlide];

At first, this didn't work for me, and then a saw in the documentation of this method that says: // Setting statusBarHidden does nothing if your application is using the default UIViewController-based status bar system.

This has to be done on the plist file, adding the key View controller-based status bar appearance set to NO. And then it worked.

Stunner
  • 12,025
  • 12
  • 86
  • 145
Debora Fortini
  • 549
  • 3
  • 3
16

In order to use the legacy UIApplication method to hide/show the status bar, your app must set a plist value for iOS 7:

View-Controller Based Status Bar Appearance = NO

This value is set to YES by default. If you change it to NO, you can use the legacy methods. If you leave it set to YES, you can still hide the status bar, but it's up to each view controller subclass in your app to override: prefersStatusBarHidden to return YES.

Any time your app needs the status bar appearance or visibility to change, and View-Controller Based Status Bar Appearance is set to YES, your outermost view controller needs to call:

setNeedsStatusBarAppearanceUpdateAnimation

jaredsinclair
  • 12,687
  • 5
  • 35
  • 56
  • I have had to apply in Custom iOS Target Properties, because in the general plist didn't work – xarly Oct 08 '13 at 16:29
16

To hide status bar in iOS7 you need 2 lines of code

  1. inapplication:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions write

    [application setStatusBarHidden:YES];
    
  2. in info.plist add this

    View-Controller Based Status Bar Appearance = NO
    
Shaik Riyaz
  • 11,204
  • 7
  • 53
  • 70
  • 2
    Just to clean this up, if you're putting this inside didFinishLaunching you can just write `[application setStatusBarHidden:YES];` or `application.statusBarHidden = YES;` – joel.d Jun 15 '14 at 01:31
  • there may be a typo in answer above. "View-Controller Based Status Bar Appearance = NO" did not work for me, but "View controller-based status bar appearance = NO" did work. – tmr Aug 10 '15 at 04:09
11

There are so many combinations suggested for this issue, but the problem is that iOS 6 and 7 use different methods to hide the status bar. I have never been successful setting the plist settings to enable the iOS6-style behaviour on iOS 7, but if you are building your app to support iOS 6+, you need to use 3 methods at once to ensure a particular view controller hides the status bar:

// for ios 7 
- (BOOL)prefersStatusBarHidden{
    return YES;
}

// for ios 6
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [[UIApplication sharedApplication] setStatusBarHidden:YES];
}
- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    // explicitly set the bar to show or it will remain hidden for other view controllers
    [[UIApplication sharedApplication] setStatusBarHidden:NO];
}

This should work regardless of your plist settings.

SaltyNuts
  • 5,068
  • 8
  • 48
  • 80
7

I had to do both changes below to hide the status bar:

Add this code to the view controller where you want to hide the status bar:

- (BOOL)prefersStatusBarHidden
{
    return YES;
}

Add this to your .plist file (go to 'info' in your application settings)

View controller-based status bar appearance --- NO

Then you can call this line to hide the status bar:

[[UIApplication sharedApplication] setStatusBarHidden:YES];
Peter Y
  • 81
  • 1
  • 2
6

Just add these 2 lines in info.plist file. It will make the fix for iOS7 and older version both.

  • Status bar is initially hidden = YES
  • View controller-based status bar appearance = NO

Navigate to the project and select Targets -> General and see the "Status Bar style ...Hide during application launch" check box will be checked. This will work.

Sid
  • 137
  • 1
  • 1
6

Try this simple method:

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

- (void)viewWillDisappear:(BOOL)animated
{
[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationNone];
}
Rajesh Loganathan
  • 11,129
  • 4
  • 78
  • 90
4

The only thing that worked for me is to add the following in your plist

<key>UIStatusBarHidden</key>
<true/>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
bartburkhardt
  • 7,498
  • 1
  • 18
  • 14
4

The easiest method I've found for hiding the status bar throughout the entire app is by creating a category on UIViewController and overriding prefersStatusBarHidden. This way you don't have to write this method in every single view controller.

UIViewController+HideStatusBar.h

#import <UIKit/UIKit.h>

@interface UIViewController (HideStatusBar)

@end

UIViewController+HideStatusBar.m

#import "UIViewController+HideStatusBar.h"

@implementation UIViewController (HideStatusBar)

//Pragma Marks suppress compiler warning in LLVM. 
//Technically, you shouldn't override methods by using a category, 
//but I feel that in this case it won't hurt so long as you truly 
//want every view controller to hide the status bar. 
//Other opinions on this are definitely welcome

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wobjc-protocol-method-implementation"

- (BOOL)prefersStatusBarHidden
{
    return YES;
}

#pragma clang diagnostic pop


@end
Ravi Gautam
  • 960
  • 2
  • 9
  • 20
mike
  • 1,441
  • 2
  • 19
  • 31
3
  1. In plist add ----

    View controller-based status bar appearance --- NO

  2. In each viewController write

    - (void) viewDidLayoutSubviews
    {
        CGRect viewBounds = self.view.bounds;
        CGFloat topBarOffset = 20.0;
        viewBounds.origin.y = -topBarOffset;
        self.view.bounds = viewBounds;
    
        [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];//for status bar style
    }
    

For status bar issue in iOS 7 but target should be 5.1 and above for the app

Maulik
  • 19,348
  • 14
  • 82
  • 137
3
-(BOOL)prefersStatusBarHidden
{
    return YES;
}
halfer
  • 19,824
  • 17
  • 99
  • 186
Thunderbird
  • 687
  • 6
  • 16
3

Many of the answers on this thread work, but it's my understanding if you're trying to do anything dynamic you'll eventually need to call:

[self performSelector:@selector(setNeedsStatusBarAppearanceUpdate)];
darkheartfelt
  • 1,078
  • 2
  • 12
  • 26
3

Steps For Hide the status bar in iOS 7:

1.Go to your application info.plist file.

2.And Set, View controller-based status bar appearance : Boolean NO

Hope i solved the status bar issue.....

chandrika
  • 394
  • 4
  • 12
3

For iOS 7 in a single view use in viewWillappear method:

[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:NO];

For display the status bar use:

[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:NO];
oscar castellon
  • 3,048
  • 30
  • 19
2

In Info Plist file Add a row for following property

Property Name : View controller-based status bar appearance

Value : NO

user842553
  • 21
  • 3
1

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

- (BOOL)prefersStatusBarHidden
    {
        return YES;
    }
Bhoopi
  • 6,523
  • 3
  • 22
  • 16
1

I tried all these options posted here on my project and they would not work. I thought it could be to do with the fact I had updated my Xcode and then the app to iOS 7 and some settings had got messed up somewhere. I decided To build a completely new project for it and after simple just setting: "Status bar is initially hidden = YES" and "View controller-based status bar appearance = NO" as stated by many others it worked correctly (i.e. no status bar).

So my advice if you are working on a project which has been updated to iOS 7 from an old version and have tried all other options is to build a new project.

Ravi Gautam
  • 960
  • 2
  • 9
  • 20
user1529408
  • 219
  • 1
  • 3
  • 10
  • I used this same technique to initially confirm that I could hide the status bar globally, for every screen, but as my app is quite "time-centric", I wanted the time display for most screens. It's only one screen I wanted to exclude it for various reasons. I ended up using the opposite of your parameters: initially hidden=NO & VC-based status bar appearance=YES. _Then_ I had to put the (BOOL)prefersStatusBarHidden method (returning YES) into the one VC where I wanted it hidden. Works nicely. I should add that my app is iOS7-only for other reasons. – bobsmells Jun 12 '14 at 16:38
1

For 2019 ...

To make an app with NO status bars,

Click info.plist, right-click to "Add row".

Add these two, with these settings:

enter image description here

That's all there is to it.

Community
  • 1
  • 1
Fattie
  • 27,874
  • 70
  • 431
  • 719
0

You can check this code, pod UIViewController+ODStatusBar

Alex Nazarov
  • 1,178
  • 8
  • 16
0

For Swift 2.0+ IOS 9

override func prefersStatusBarHidden() -> Bool {
return true
}
Irshad Qureshi
  • 807
  • 18
  • 41
0

To hide status bar for specific viewController

- (BOOL)prefersStatusBarHidden {
    return YES;
}

For setting status bar Hidden for application:

  • set View controller-based status bar appearancetoNO in .plist and in application: didFinishLaunchingWithOptions: set: [application setStatusBarHidden:YES];

    Note: setStatusBarHidden: deprecated

OR

  • in Project settings -> General Tab ->Deployment Info

    Check Hide Status bar box.

Lal Krishna
  • 15,485
  • 6
  • 64
  • 84
-1
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
application.statusBarHidden = YES;
return YES;
}
Evan Ische
  • 76
  • 1
  • 7
-7

I'm not sure why you "can't login to the Apple Developer Forums", but (without violating the NDA) you can also hide your statusBar through Xcode. It's a general setting on your application target. enter image description here

Jake
  • 3,973
  • 24
  • 36