[ios] How to hide a status bar in iOS?

I can hide a status bar in my app:

- (void)viewDidLoad{
    [[UIApplication sharedApplication] setStatusBarHidden:YES];
    [super viewDidLoad];
    }

When I chose my launch image and start it first time, it's status bar over a picture. How can I hide this?

This question is related to ios statusbar

The answer is


To hide status bar for each individual view controller programmatically, use any of the following two procedures:

Procedure 1:

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

Procedure 2:

-(BOOL)prefersStatusBarHidden {

       return YES;

}

To hide status bar for the entire application, we should follow the given below procedure:

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

Click here to view screenshot


You need to add this code in your AppDelegate file, not in your Root View Controller

Or add the property Status bar is initially hidden in your plist file

enter image description here

Folks, in iOS 7+

please add this to your info.plist file, It will make the difference :)

UIStatusBarHidden UIViewControllerBasedStatusBarAppearance

enter image description here

For iOS 11.4+ and Xcode 9.4 +

Use this code either in one or all your view controllers

override var prefersStatusBarHidden: Bool { return true }


I had the same problem, but its an easy fix! Just set

status bar is initially hidden = YES

then add an row by clicking on the plus right after the text status bar is initially hidden, then set the text to

view controller-based status bar appearance

by clicking the arrows, and set it to NO

Hope this helps!


Well the easiest way that I do it is by typing the following into the .m file.

- (BOOL) prefersStatusBarHidden
{
    return YES;
}

This should work!


It's working for me ,

Add below code into the info.plist file ,

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

Hopes this is work for some one .


In info.plist

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

In view controller.m

- (BOOL) prefersStatusBarHidden
{
    return YES;
}

What helped me is this (changing plist file):

  1. set Status bar is initially hidden = YES
  2. add row: View controller-based status bar appearance = NO

Hide StatusBar - plist settings


add this key key from dropdownlist in "info.plist" and voila you will no more see top bar that includes elements something like GSM,wifi icon etc.
enter image description here


Put this code to your view controller in which you hide status bar:

- (BOOL)prefersStatusBarHidden {return YES;}

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

A complete solution in swift, in your view controller

// you can use your own logic to determine if you need to hide status bar
// I just put a var here for now
var hideStatusBar = false
override func preferStatusBarHidden() -> Bool {
    return hideStatus
}


// in other method to manually toggle status bar
func updateUI() {
    hideStatusBar = true
    // call this method to update status bar
    prefersStatusBarHidden()
}

I am supporting iOS 5, 6, & 7. My app is iPad only. I needed to use all of the following:

[[UIApplication sharedApplication] setStatusBarHidden:YES];

View Controller:

- (BOOL)prefersStatusBarHidden{ return YES; }

Info.plist

    <key>UIStatusBarHidden</key>
    <string>YES</string>

    <key>UIStatusBarHidden~ipad</key>
    <true/>

    <key>UIViewControllerBasedStatusBarAppearance</key>
    <string>NO</string>

In iOS 7 status bar appearance depends on UIViewController as default. To hide status bar globally, in info.plist use NO value for UIViewControllerBasedStatusBarAppearance key and use UIApplication's setStatusBarHidden method with YES BOOL value.


Just check the box on Targets/Summary iPad Deployment Info and you status bar will disappear. It works on my apps.