61

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?

The Guy with The Hat
  • 10,836
  • 8
  • 57
  • 75
  • 1
    I created a `BaseViewController` and added this code to it's `viewDidLoad`. This makes sure that I have it applied to all my view controllers. I also added `View controller-based status bar appearance` to `NO` under `Info` – Mahendra Liya Nov 07 '13 at 14:18

15 Answers15

131

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 }

Charan
  • 4,940
  • 3
  • 26
  • 43
78

Add the following code to your view controller:

if ([self respondsToSelector:@selector(setNeedsStatusBarAppearanceUpdate)]) {
    // iOS 7
    [self performSelector:@selector(setNeedsStatusBarAppearanceUpdate)];
} else {
    // iOS 6
    [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationSlide];
}

- (BOOL)prefersStatusBarHidden {
    return YES;
}
s1m0n
  • 7,825
  • 1
  • 32
  • 45
Hardik Darji
  • 3,633
  • 1
  • 30
  • 30
64

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

Arkady
  • 3,196
  • 24
  • 19
42

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

- (BOOL)prefersStatusBarHidden {return YES;}
  • beware, this will work on ios7 only: - (BOOL)prefersStatusBarHidden NS_AVAILABLE_IOS(7_0); – Viren Mar 12 '14 at 04:13
12

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.

Alex Markman
  • 1,450
  • 1
  • 13
  • 15
11

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

Zen Of Kursat
  • 2,672
  • 1
  • 31
  • 47
2

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 .

Jaywant Khedkar
  • 5,941
  • 2
  • 44
  • 55
1

In info.plist

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

In view controller.m

- (BOOL) prefersStatusBarHidden
{
    return YES;
}
jeet.chanchawat
  • 5,842
  • 5
  • 38
  • 59
  • I wanted to have a handy note... I come to this link almost once in a week to copy code snippet... then I have to search all different answers. – jeet.chanchawat Jun 25 '14 at 09:59
1

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>
BuvinJ
  • 10,221
  • 5
  • 83
  • 96
0

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

Charan
  • 4,940
  • 3
  • 26
  • 43
  • On ios 7 and xcode 5, Take a look at this post, it saved my job. http://stackoverflow.com/questions/18059703/cannot-hide-status-bar-in-ios7 – Marc Millet Oct 10 '13 at 09:26
0

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!

The Guy with The Hat
  • 10,836
  • 8
  • 57
  • 75
JELLYFUN
  • 39
  • 1
0

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

- (BOOL) prefersStatusBarHidden
{
    return YES;
}

This should work!

Trent
  • 1
0
-(void) viewWillAppear:(BOOL)animated
{
     [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationSlide];
}
Gaurav Gilani
  • 1,584
  • 14
  • 18
  • 1
    This answer was flagged as low quality, can you please update your answer to describe why this works? – Daniel May 21 '14 at 13:03
0

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()
}
codingrhythm
  • 1,456
  • 14
  • 26
  • As of Xcode 8.1 there seems to be no function preferStatusBarHidden to override. Instead the line "let preferStatusBarHidden : Bool = true" in ViewController did it for me. Regards. – dezember Dec 11 '16 at 12:36
0

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

Ronan Boiteau
  • 9,608
  • 6
  • 34
  • 56
KSR
  • 1,699
  • 15
  • 22