Cannot hide status bar in iOS7
Asked Answered
A

26

271

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

Adora answered 5/8, 2013 at 13:42 Comment(3)
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 ;-)Brothel
possible duplicate of Status bar won't disappearEngrail
how to hide status bar programmatically particular ViewController ?Prot
K
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

Khiva answered 31/8, 2013 at 16:1 Comment(6)
For reference, the raw value stored in the actual Info.plist file is called UIViewControllerBasedStatusBarAppearance.Burdened
I have had to apply in Custom iOS Target Properties, because in the general plist didn't workHillier
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.Hobbes
I really don't know why Apple has changed this ! Thanks :)Disquieting
You also need to set Status bar is initially hidden to YES.Honan
This doesn't work. If you add the Status bar is initially hidden: YES the app freezes up and won't run.Smokedry
T
278

Add method in your view controller.

- (BOOL)prefersStatusBarHidden {
    return YES;
}
Thant answered 11/9, 2013 at 12:13 Comment(10)
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!Skiffle
+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.Formulate
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 calledOpaline
Sorry, it actually works on a blank project, but is not working on mine for some reason.Opaline
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.Thant
Worked for me in an existing project for iOS6 and iOS7.Triplet
this should be the correct answer as it solves the UIImagePickerController bugPartin
@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.Laellaertes
@Laellaertes Did you find a solution for iOS8?People
@Laellaertes 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.Thant
B
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.

Byword answered 19/9, 2013 at 8:27 Comment(1)
Yep, this worked for me also. Without setting "Status bar is initially hidden" option to YES its not working as expected. Thx.Seema
I
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.

Inofficious answered 30/8, 2013 at 1:0 Comment(0)
W
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

Write answered 17/9, 2013 at 17:22 Comment(1)
I have had to apply in Custom iOS Target Properties, because in the general plist didn't workHillier
G
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
    
Gelsenkirchen answered 11/11, 2013 at 12:1 Comment(2)
Just to clean this up, if you're putting this inside didFinishLaunching you can just write [application setStatusBarHidden:YES]; or application.statusBarHidden = YES;Deneendenegation
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.Allegraallegretto
B
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.

Brunn answered 10/3, 2014 at 18:26 Comment(0)
F
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];
Fillian answered 30/12, 2013 at 1:50 Comment(0)
R
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.

Research answered 11/1, 2014 at 5:25 Comment(0)
C
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];
}
Calamondin answered 21/1, 2014 at 12:26 Comment(0)
T
4

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

<key>UIStatusBarHidden</key>
<true/>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
Tegument answered 15/10, 2013 at 19:45 Comment(0)
V
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
Voletta answered 10/1, 2014 at 2:0 Comment(1)
the best real, iOS7, non-fakey solution, greatFredkin
S
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

Sequence answered 1/10, 2013 at 5:4 Comment(0)
S
3
-(BOOL)prefersStatusBarHidden
{
    return YES;
}
Stator answered 9/10, 2013 at 10:24 Comment(0)
M
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)];
Milicent answered 1/12, 2013 at 1:49 Comment(0)
A
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.....

Analysis answered 30/1, 2014 at 11:48 Comment(0)
I
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];
Indeed answered 14/7, 2014 at 5:39 Comment(0)
C
2

In Info Plist file Add a row for following property

Property Name : View controller-based status bar appearance

Value : NO

Camey answered 9/10, 2013 at 11:33 Comment(0)
I
1

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

- (BOOL)prefersStatusBarHidden
    {
        return YES;
    }
Incantation answered 25/9, 2013 at 12:3 Comment(0)
B
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.

Ballesteros answered 1/4, 2014 at 18:59 Comment(1)
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.Cabman
F
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.

Fredkin answered 28/7, 2019 at 18:19 Comment(0)
H
0

You can check this code, pod UIViewController+ODStatusBar

Hohenzollern answered 26/6, 2015 at 10:24 Comment(0)
S
0

For Swift 2.0+ IOS 9

override func prefersStatusBarHidden() -> Bool {
return true
}
Squilgee answered 8/2, 2016 at 9:19 Comment(0)
T
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.

Tarragona answered 21/3, 2017 at 11:49 Comment(0)
E
-1
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
application.statusBarHidden = YES;
return YES;
}
Equilateral answered 26/12, 2013 at 21:13 Comment(2)
Question explicitly mentions that this approach doesn't work. Please, read question carefully before answering.Fluellen
As long as view controller-based status bar appearance is set to NO, it's the cleanest approach.Equilateral
B
-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

Brothel answered 5/8, 2013 at 13:45 Comment(1)
nope, works like a charm. the forums have been up for a while now.Brothel

© 2022 - 2024 — McMap. All rights reserved.