How to hide a status bar in iOS? - 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?

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
Folks, in iOS 7+
please add this to your info.plist file, It will make the difference :)
UIStatusBarHidden
UIViewControllerBasedStatusBarAppearance
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 }

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;
}

What helped me is this (changing plist file):
set Status bar is initially hidden = YES
add row: View controller-based status bar appearance = NO

Put this code to your view controller in which you hide status bar:
- (BOOL)prefersStatusBarHidden {return YES;}

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.

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.

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;
}

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>

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

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!

-(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()
}

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

Related

Hide the status bar in ios 9

How do you hide the status bar in ios 9?
This is now deprecated:
[UIApplication sharedApplication] setStatusBarHidden:YES];
Swift-3
override var prefersStatusBarHidden: Bool {
return true
}
I got the Information From Here
Change func to var
Delete ()
Change -> to :
This works because a computed variable has a getter function, so the function you were implementing before simply turns into the getter function
2016 onwards: simple Thing like
On your info.plist add the following two property for statusBar Hidden
View controller-based status bar appearance (Boolean: NO)
Status bar is initially hidden (Boolean: YES)
By Source
<key>UIStatusBarHidden</key>
<true/>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
or
Old answers ! ...
add application.statusBarHidden in didFinishLaunchingWithOptions
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
application.statusBarHidden = YES;
return YES;
}
and add
in info.plist add this View controller-based status bar appearance set NO
View controller-based status bar appearance = NO
viewcontroller based hidden set
Add method in your view controller.
Objective -C
- (BOOL)prefersStatusBarHidden {
return YES;
}
Swift upto 2
override func prefersStatusBarHidden() -> Bool {
return true
}
(GOOD) 2016.5.17 in iOS 9.0 worked nicely.
Updated Answer
Go to Info.plist file
Hover on one of those lines and a (+) and (-) button will show up.
Click the plus button to add new key
Type in start with capital V and automatically the first choice will be View controller-based status bar appearance. Add that as the KEY.
Set the VALUE to "NO"
Go to you AppDelegate.m for Objective-C (for swift language: AppDelegate.swift)
Add the code, inside the method
For Objective-C:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[application setStatusBarHidden:YES];
return YES;
}
For Swift:
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject:AnyObject]?) -> Bool {
application.statusBarHidden = true
return true
}
in info.plist add the following two property.
View controller-based status bar appearance (NO)
Status bar is initially hidden (YES)
I know that the documentation of setStatusBarHidden: does not mention on what use instead. But the header of UIApplication does.
// Setting statusBarHidden does nothing if your application is using the default UIViewController-based status bar system.
#property(readwrite, nonatomic,getter=isStatusBarHidden) BOOL statusBarHidden NS_DEPRECATED_IOS(2_0, 9_0, "Use -[UIViewController prefersStatusBarHidden]");
- (void)setStatusBarHidden:(BOOL)hidden withAnimation:(UIStatusBarAnimation)animation NS_DEPRECATED_IOS(3_2, 9_0, "Use -[UIViewController prefersStatusBarHidden]");
Here is stated that you should use the prefersStatusBarHidden on UIViewController and use view controller based statusbar styles.
All you need to do now is configure whether the view controller needs to show of hide the status bar. Like so :
- (BOOL)prefersStatusBarHidden {
return YES;
}
Here's how do you easily return a control over status bar visibility for iOS 9+ and Swift 3+:
Add View controller-based status bar appearance key with YES value to Info.plist.
Add this variable to the view controller:
private var isStatusBarHidden = false {
didSet {
setNeedsStatusBarAppearanceUpdate()
}
}
Override prefersStatusBarHidden property:
override var prefersStatusBarHidden: Bool {
return isStatusBarHidden
}
That's it. Now you are able to call isStatusBarHidden = true and isStatusBarHidden = false whenever you want.
An easy approach would be to set the windowLevel of the Application to be either normal or statusBar based on your needs, so to start
Objective-C
To Hide the Status Bar
UIApplication.sharedApplication.keyWindow.windowLevel = UIWindowLevelStatusBar;
To Show the Status Bar
UIApplication.sharedApplication.keyWindow.windowLevel = UIWindowLevelNormal;
Also add the Key (View controller-based status bar appearance) with boolean value NO.
If for some reason you need View controller-based status bar appearance equal to YES (for example to keep status bar white)
on AppDelegate's didFinishLaunchingWithOptions method or wherever you setup your navigationController:
yourNavigationController.navigationBar.barStyle = .black
then use alex-staravoitau's awesome answer and add this code wherever you'll be hiding the status bar:
override var preferredStatusBarStyle: UIStatusBarStyle {
return .lightContent
}
I'm not sure if this is the right way to achieve this result, but it worked for me and I hope it helps someone else too :)
In most of the iOS it will work. I have tested with iOS 10.
Open info.plist
"View controller-based status bar appearance" set to NO
"Status bar is initially hidden" set to YES
Done

Hide status bar in iphone/ipad apps

I'm working on an application for iPhone iPad.
My test iPhone (v4) is on iOS 6.
My test iPad is on iOS 7.
I'd like to remove both statuses bar from the whole application.
Here's what I've tried :
In info.plist, I've set Status bar is initially hidden to YES and View controller based status bar to NO
This didn't work.
So I've set View controller based status bar to YES and in my main view controller I've added :
- (BOOL)prefersStatusBarHidden{
return YES;
}
Though this function never gets called.
In this same controller I've added this to loadview:
[[UIApplication sharedApplication] setStatusBarHidden:YES];
This worked for the iPhone, but the bar still shows up on iPad.
Thanks for your help.
EDIT :
I also have checked "Hide during application launch" in project settings.
EDIT :
Here are two screenshots of my project settings.
http://imgur.com/a/VXZTk
As you can see I've tried the answers of the question you voted this as a duplicate to.
If I'm not doing it wrong, thanks for voting to re-open this question.
You need to have two things to have the status bar hidden throughout whole app in all iOS versions
In info.plist View controller based status bar set to NO . (For iOS 7)
In your applicationDidFinishLaunching add [[UIApplication sharedApplication] setStatusBarHidden:YES]; or simply [app setStatusBarHidden:YES]
Now you can optionally set Status bar is initially hidden to YES also to hide status bar when app launches.
Also if you dont want status bar to be hidden throughout the app.
remove [[UIApplication sharedApplication] setStatusBarHidden:YES]
and override prefersStatusBarHidden in your ViewControllers and return YES or NO
- (BOOL)prefersStatusBarHidden{
return YES;
}
If you set Status bar is initially hidden to YES, it will work fine.
Anyways Have you tried below methods?
-(void)viewDidLoad
{
[super viewDidLoad];
if ([self respondsToSelector:#selector(setNeedsStatusBarAppearanceUpdate)])
{
[self prefersStatusBarHidden];
[self setNeedsStatusBarAppearanceUpdate];
}
}
-(BOOL)prefersStatusBarHidden
{
return YES;
}
- (UIViewController *)childViewControllerForStatusBarHidden
{
return nil;
}
Thanks!
Just needed to set deployment infos to universal.
Click xCode project/your target/General/Deployement Info, then check the "hide during application launch"

Presenting a full-screen view that hides the status bar [duplicate]

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?
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
Folks, in iOS 7+
please add this to your info.plist file, It will make the difference :)
UIStatusBarHidden
UIViewControllerBasedStatusBarAppearance
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 }
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;
}
What helped me is this (changing plist file):
set Status bar is initially hidden = YES
add row: View controller-based status bar appearance = NO
Put this code to your view controller in which you hide status bar:
- (BOOL)prefersStatusBarHidden {return YES;}
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.
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.
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;
}
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>
Just check the box on Targets/Summary iPad Deployment Info and you status bar will disappear.
It works on my apps.
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!
-(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()
}
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

Changing status bar style ios 7?

I am trying to change the status bar style of one of my viewcontrollers. I have put this
set the view based status bar to YES in the plist
2.
-(UIStatusBarStyle)preferredStatusBarStyle{
return UIStatusBarStyleLightContent;
}
Added this also
[self setNeedsStatusBarAppearanceUpdate]
It works i.e I can see the font color white but just after some time it changes back to its previous type..
If you are experiencing status bar changing color itself during runtime
try setting set the UIViewControllerBasedStatusBarAppearance to NO in the plist.
And inside your viewController.. set the appearance call inside
-(void)viewDidLayoutSubviews
{
if ([self respondsToSelector:#selector(setNeedsStatusBarAppearanceUpdate)]) {
[self setNeedsStatusBarAppearanceUpdate];
}
}
write following code
-(void)viewWillAppear:(BOOL)Animated{
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
}
This is the only thing I could get working for iOS7
- (UIStatusBarStyle)preferredStatusBarStyle
{
return UIStatusBarStyleLightContent;
}
You can check this code, a little trick – but useful sometimes.

How to set status bar's content color to white on iOS 7

My App’s background colour is black. Cause the whole view is below the status bar on iOS 7, the content on the status bar will hard to be distinguished. So how to change status bar’s content colour to white?
I've tried preferredStatusBarStyle and several other ways, but failed.
Set "View controller-based status bar appearance” to NO in your info.list file;
Insert
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
to -application:didFinishLaunchingWithOptions: of the AppDelegate.m.
Note: UIStatusBarStyleDefault is the default value for the status bar style, it'll show black content instead. Both UIStatusBarStyleBlackTranslucent & UIStatusBarStyleBlackOpaque are deprecated in iOS 7.0.
UPDATE for iOS 9:
As #ZakariaDarwish mentioned, the method -setStatusBarStyle is deprecated in iOS 9. (Note: The original question was asked for iOS 7 long time ago, and I don't support it now, the new solution below works for me under iOS 9, hence update here.)
So, the only way left (at least for now) is to implement -preferredStatusBarStyle in your view controller (remember to set "View controller-based status bar appearance" back to YES).
You can invoke UIViewController's instance method -setNeedsStatusBarAppearanceUpdate once value changed in -preferredStatusBarStyle or -prefersStatusBarHidden.
There're also two methods -childViewControllerForStatusBarStyle & -childViewControllerForStatusBarHidden to return the preferred style from child view controller as you want.
e.g., if you used below methods
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault animated:YES];
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent animated:YES];
to switch status bar style before, you can use code sample below
- (void)shouldChangeStatusBarStyleToLightContent:(BOOL)toLightContent
animated:(BOOL)animated
{
_shouldChangeStatusBarStyleToLightContent = toLightContent;
if (animated) {
[UIView animateWithDuration:.3f animations:^{ [self setNeedsStatusBarAppearanceUpdate]; }];
} else {
[self setNeedsStatusBarAppearanceUpdate];
}
}
- (UIStatusBarStyle)preferredStatusBarStyle
{
return (_shouldChangeStatusBarStyleToLightContent ? UIStatusBarStyleLightContent : UIStatusBarStyleDefault);
}
for this updated solution now.
In your *-Info.plist file:
Set 'View controller-based status bar appearance' to NO
Set 'Status bar style' to UIStatusBarStyleLightContent
Alternatively you can specify Status bar style as 'Black Opaque' or 'Black Translucent' in General tab of the Target.(in Xcode 5.0.1) But they are obsoleted values.
I use this in main controller:
- (UIStatusBarStyle)preferredStatusBarStyle
{
return UIStatusBarStyleLightContent;
}
Place these two keys in info.plist
Here a short and simple solution to set status bar color White
1) First copy this line View controller-based status bar appearance to in your .plist file and set Boolean NO;
2) In your AppDelegate.m file under didFinishLaunchingWithOptions paste this
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent animated:YES];
[[UIApplication sharedApplication] setStatusBarHidden:NO];
OR add in .plist
iOS 9 (deprecated warning workaround)
[UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
#ifdef __IPHONE_7_0
# define STATUS_STYLE UIStatusBarStyleLightContent
#else
# define STATUS_STYLE UIStatusBarStyleBlackTranslucent
#endif
[[UIApplication sharedApplication] setStatusBarStyle:STATUS_STYLE animated:YES];
If your application have different status bar's content color for each view controller the preferred method would be implementing
override var preferredStatusBarStyle: UIStatusBarStyle {
return .lightContent
}
If you need to change the bar's content color globally throughout the application then add following lines of code in your didFinishLaunchingWithOptions method in AppDelegate
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
UIApplication.shared.statusBarStyle = .lightContent
return true
}
Wait setting the statusBarStyle does nothing if your application is using the default UIViewController-based status bar system. For this
Set "View controller-based status bar appearance” to NO in your info.list file
Just a note, since this was there. If you are using a UINavigationController, you can throw this into the view controllers viewDidLoad method:
self.navigationController.navigationBar.barStyle = UIStatusBarStyleLightContent;
To do it programmatically in Swift 3 try this anywhere in your view controller.
override var preferredStatusBarStyle: UIStatusBarStyle {
return .lightContent
}
I also set the plist key "View controller-based status bar appearance" to YES.

Resources