223

In my iOS video app status bar is hidden in some view controllers. I have done this using following code.

[[UIApplication sharedApplication] setStatusBarHidden:YES];
  • It works for iOS 5 and iOS 6 , but not in iOS 7.

  • I tried with this in particular view controller,

Eg:

-(BOOL)prefersStatusBarHidden { return YES; }

It works well, but I cant show status bar again in the parent view controller.

Susitha
  • 3,239
  • 5
  • 25
  • 39
  • 1
    http://stackoverflow.com/questions/18059703/cannot-hide-status-bar-in-ios7 – Melih Büyükbayram Oct 24 '13 at 15:37
  • 1
    If the status bar style is set in the Storyboard, after changing the "View controller-based status bar" (below), the style may have to be set in the plist because the view controller setting will no longer be used. http://stackoverflow.com/questions/18924345/how-to-change-status-bar-style-during-launch-on-ios-7 – Matt Aug 13 '14 at 00:48
  • 1
    I answered in another question. Try this. [ the easiest way to hide status bar programmatically][1] [1]: http://stackoverflow.com/a/27339754/3718498 – wataru Dec 07 '14 at 05:01
  • 1
    I used a trick for it – I published it as pod https://cocoapods.org/pods/UIViewController+ODStatusBar, I hope it will be useful for anyone – Alex Nazarsky Jun 26 '15 at 10:15
  • The answers here have now been deprecated. I had trouble finding the correct answer for iOS 9 when hiding the status bar **FOR JUST THE LAUNCH SCREEN**, so linking below so it's hopefully easier for others to find how to do that: http://stackoverflow.com/questions/34413848/cant-hide-status-bar-on-launch – Ben Jul 11 '16 at 04:37

21 Answers21

279

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

enter image description here

Rajneesh071
  • 29,619
  • 13
  • 57
  • 72
197

Add the following to your Info.plist:

<key>UIStatusBarHidden</key>
<true/>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>

Image

Shekhar Gupta
  • 6,056
  • 3
  • 27
  • 49
114

Add following line in viewdidload

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

and add new method

  - (BOOL)prefersStatusBarHidden {
          return YES;
  }

also change info.plist file View controller-based status bar appearance" = NO

its works for me

Community
  • 1
  • 1
Hitesh Vaghela
  • 1,625
  • 1
  • 11
  • 11
  • Thanx this one working for me but I need to add below row in plist also. "View controller-based status bar appearance" = NO i,e Add following line in viewdidload [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationFade]; and add new method - (BOOL)prefersStatusBarHidden { return YES; } Add "View controller-based status bar appearance" = NO in Plist file – sandy Dec 20 '13 at 12:30
  • `prefersStatusBarHidden` is what did the trick for me (whether with this solution of with other similar ones) – Abdo May 11 '15 at 13:28
34

In the Plist add the following properties.

Status bar is initially hidden = YES

View controller-based status bar appearance = NO

now the status bar will hidden.

Gurumoorthy Arumugam
  • 2,091
  • 1
  • 24
  • 38
28

Try this simple method:


Objective-C:

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

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated]
    [[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationNone];
}

Swift:

override func viewWillAppear(animated: Bool) 
{
    super.viewWillAppear(animated)
    UIApplication.sharedApplication().setStatusBarHidden(true, withAnimation: UIStatusBarAnimation.None)
}

override func viewWillDisappear(animated: Bool) 
{
    super.viewWillDisappear(animated)
    UIApplication.sharedApplication().setStatusBarHidden(false, withAnimation: UIStatusBarAnimation.None)
}
Rajesh Loganathan
  • 10,635
  • 4
  • 74
  • 88
14

I did the following and it seems to work (even in iOS 8):

- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    if ([self respondsToSelector:@selector(setNeedsStatusBarAppearanceUpdate)]) {

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

- (BOOL)prefersStatusBarHidden {
    return YES;
}
smartbot
  • 141
  • 1
  • 3
13
  • UIApplication.setStatusBarX are deprecated as of iOS9
  • It's deprecated to have UIViewControllerBasedStatusBarAppearance=NO in your info.plist
  • So we should be using preferredStatusBarX in all our view controllers

But it gets more interesting when there's a UINavigationController involved:

  • If navigationBarHidden = true, the child UIViewController's preferredStatusBarX are called, since the child is displaying the content under the status bar.
  • If navigationBarHidden = false, the UINavigationController's preferredStatusBarX are called, after all it is displaying the content under the status bar.
  • The UINavigationController's default preferredStatusBarStyle uses the value from UINav.navigationBar.barStyle. .Default = black status bar content, .Black = white status bar content.
  • So if you're setting barTintColor to some custom colour (which you likely are), you also need to set barStyle to .Black to get white status bar content. I'd set barStyle to black before setting barTintColor, in case barStyle overrides the barTintColor.
  • An alternative is that you can subclass UINavigationController rather than mucking around with bar style.
  • HOWEVER, if you subclass UINavigationController, you get no control over the status bar if navigationBarHidden = true. Somehow UIKit goes direct to the child UIViewController without asking the UINavigationController in this situation. I would have thought it should be the UINavigationController's responsibility to ask the child >shrugs<.
  • And modally displayed UIViewController's only get a say in the status bar if modalPresentationStyle = .FullScreen.
  • If you've got a custom presentation style modal view controller and you really want it to control the status bar, you can set modalPresentationCapturesStatusBarAppearance = true.
Chris
  • 37,118
  • 43
  • 178
  • 226
9

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

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

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

     View-Controller Based Status Bar Appearance = NO
    
Shaik Riyaz
  • 10,085
  • 7
  • 48
  • 67
8

For better understanding add some photos with comments:

App before any changes

enter image description here

Found in your Project Navigator folder named Supporting Files and click on *.plist file

enter image description here

After you will get different setting of your app showed. You need to add 2 keys UIStatusBarHidden and UIViewControllerBasedStatusBarAppearance. You can do this simply clicking on + button

enter image description here

After pressing + you can choose one of the key - just start to type.

Correct version:

enter image description here

And finally application after applying this changes:

enter image description here

Also, you can find alternative solution here

hbk
  • 9,872
  • 9
  • 82
  • 110
8

In iOS10 all I needed to do is override the prefersStatusBarHidden var in my RootViewController (Swift):

override var prefersStatusBarHidden: Bool {
    return true
}
andrewz
  • 3,682
  • 3
  • 37
  • 57
7

Try that;

[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone];
Kemal Can Kaynak
  • 1,533
  • 13
  • 24
  • Great. I was able to use this to hide the status bar on the view controller it wasn't needed on then unhide it once the user logged in. – LondonGuy Oct 05 '14 at 06:28
7

Swift 5

Use following steps to hide iOS Status Bar:

  1. Open on Info.plist.
  2. Add new key View controller-based status bar appearance and value set to NO.
  3. Add new key Status bar is initially hidden and value set to YES.
  4. Re-compile project.
  5. Status bar should hidden on iOS phone now.

Final Settings Screenshot:

Final Settings

This is working on Xcode 10.2

Jerry Chong
  • 3,606
  • 1
  • 27
  • 29
5

To hide your status bar in iOS7:

Open Your plist-file, then add a add a row called "View controller-based status bar appearance" and set its value to NO.

katzenhut
  • 1,722
  • 18
  • 26
Manju
  • 4,083
  • 2
  • 16
  • 12
5

Here is the Swift version (pre iOS9):

override func viewWillAppear(animated: Bool) {
    super.viewWillAppear(animated)
    UIApplication.sharedApplication().setStatusBarHidden(true, withAnimation: UIStatusBarAnimation.None)
}

override func viewWillDisappear(animated: Bool) {
    super.viewWillDisappear(animated)
    UIApplication.sharedApplication().setStatusBarHidden(false, withAnimation: UIStatusBarAnimation.None)
}

This also works (iOS7+):

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

You also need to call:

setNeedsStatusBarAppearanceUpdate()

in say viewDidLoad().

Note that if you use a SplitView controller, or some other container view controller, you also need to have it return your class when its sent childViewControllerForStatusBarHidden. One way to do this is have a public weak var for say statusController, and return it in this overridden method.

David H
  • 39,114
  • 12
  • 86
  • 125
Esqarrouth
  • 35,175
  • 17
  • 147
  • 154
  • 1
    The top block is deprecated in iOS8 - use your second approach. And thanks! I edited the code to add another mandatory call. – David H Nov 05 '15 at 22:30
5

iOS 9 onwards :

As statusBarHidden method was Deprecated from iOS9 you need to add two values in plist as below :

<key>UIStatusBarHidden</key>
<true/>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>

or by User Interface Please refre below image :

enter image description here

As statusBarHidden is Deprecated from iOS9 :

@property(readwrite, nonatomic,getter=isStatusBarHidden) BOOL statusBarHidden NS_DEPRECATED_IOS(2_0, 9_0, "Use -[UIViewController prefersStatusBarHidden]") __TVOS_PROHIBITED;

Ketan P
  • 3,899
  • 3
  • 28
  • 34
5

FIXED SOLUTION FOR SWIFT 3+ (iOS 9, 10)

1- In info.plist set below property

enter image description here

2- Paste below code to Root controller , To

 private var isStatusBarHidden = true {
        didSet {
            setNeedsStatusBarAppearanceUpdate()
        }
    }

    override var prefersStatusBarHidden: Bool {
        return isStatusBarHidden
    }

You can call isStatusBarHidden = true and isStatusBarHidden = false where you want to hide/show status bar

MANISH PATHAK
  • 2,425
  • 3
  • 24
  • 28
4

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

bLacK hoLE
  • 681
  • 1
  • 7
  • 20
4

Steps for hide status bar in iOS
1. open AppDelegate.m file, add application.statusBarHidden in didFinishLaunchingWithOptions method

 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    application.statusBarHidden = YES;
    return YES;
    }
  1. open info.plist and set

View controller-based status bar appearance set NO

Ashu
  • 2,867
  • 29
  • 30
2

From UIKit>UIApplication.h:

// Setting statusBarHidden does nothing if your application is using the default UIViewController-based status bar system.
@property(nonatomic,getter=isStatusBarHidden) BOOL statusBarHidden;
- (void)setStatusBarHidden:(BOOL)hidden withAnimation:(UIStatusBarAnimation)animation NS_AVAILABLE_IOS(3_2);

So should set View controller-based status bar appearance to NO

Tony
  • 4,042
  • 20
  • 46
2

To answer the Susitha's question: use setNeedsStatusBarAppearanceUpdate. This will make a call to prefersStatusBarHidden to refresh with your desired status bar state. Try this:

    @property (nonatomic, getter=isHideStatusBar) BOOL hideStatusBar; // Give this a default value early

    - (BOOL)prefersStatusBarHidden {
        return self.isHideStatusBar;
    }

    - (void)someMethod {
    // triggered by an event or user action
    [self setHideStatusBar:YES];
    [self setNeedsStatusBarAppearanceUpdate];
    }

If you want to see the status bar again, set your property hideStatusBar (or whatever you call it) to NO. Call preferStatusBarHidden indirectly by making another call to

[self setNeedsStatusBarAppearanceUpdate]
smileBot
  • 18,797
  • 7
  • 60
  • 62
1

Update for Swift 3:

Update Info.plist with the following info:

View controller-based status bar appearance: NO

Then, in a ViewController or elsewhere:

UIApplication.shared.isStatusBarHidden = true

Prazgaitis
  • 27
  • 1
  • 4