Hide status bar in iphone/ipad apps - ios

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"

Related

Runtime Hide / Show Status Bar iOS 9+

I have an application where it is important to hide / show the status bar and switch its style on the fly. Previously, it was very easy with the following calls:
[[UIApplication sharedApplication] setStatusBarHidden:NO];
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
But they have been deprecated, and I don't quite understand how the new methods work. I was able to set the style and initial visibility by adding the following line to the plist:
View controller-based status bar appearance = YES
And then adding the following methods to my view controller:
- (UIStatusBarStyle)preferredStatusBarStyle
{
return UIStatusBarStyleDefault;
}
- (BOOL)prefersStatusBarHidden
{
return NO;
}
This works fine on the view controllers as a whole (as a static setting that gets called when the view is initialized), but I am unable to change them on the fly, which is what I need.
How could I achieve this?
I hate to answer my own question, but after doing some digging, I found how to call the method manually. First, I created a BOOL variable that can be switched on the fly and then returned in the prefersStatusBarHidden method.
- (BOOL)prefersStatusBarHidden
{
return isStatusBarHidden;
}
Then, whenever I wanted to hide/show the status bar, I changed the value of isStatusBarHidden and forced the view to check if its staus bar needs to be updated like so:
isStatusBarHidden = NO;
[self setNeedsStatusBarAppearanceUpdate];
Works perfectly for me on devices running iOS9 and above.

iOS Status bar turned black by Photo Framework

My app uses white status bar text throughout. I've accomplished this through numerous settings below:
1/ In Info.plist I set: View controller-based status bar appearance to "NO"
2/ In - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions I set [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
3/ I implemented the following in the VC I am asking about here:
- (UIStatusBarStyle) preferredStatusBarStyle {
return UIStatusBarStyleLightContent;
}
4/ In Storyboard I set the Navigation Bar Style to "Black"
So, a ton of different ways to make sure a simple status bar stays with white text. This is working throughout except for when the users goes to the picture library or the user goes to take a picture. This of course launches Apple's framework which uses a black status bar. That is fine for those controllers as again they are dictated by Apple. However, when the user then cancels or chooses an image and are returned to my controllers, the status bar stays black. I've tried the following when it returns: [self setNeedsStatusBarAppearanceUpdate] but that also does not work.
How can I get the status bar to return to white text after it returns from the Apple controlled photo picker views? I am working with iOS 8 although a check shows that this same problem occurs in 7.1. This happens with both the simulator and real devices.
I found the answer which was to repeat what I did in my step 2 above within the VC that the image picker returns to. So in viewWillAppear I execute: [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent]; again. Seems like a lot of different ways just to get a status bar to stay white, but now it does under all circumstances.
I guess it will resolve your problem as it resolves mine
Write the code for UIImagePicker and its delegate, add willShowViewController method which is delegate of UINavigationController.
There set the status bar style to LightContent.
- (void)navigationController:(UINavigationController *)navigationController
willShowViewController:(UIViewController *)viewController
animated:(BOOL)animated {
if (([navigationController isKindOfClass:[UIImagePickerController class]] &&
(((UIImagePickerController *)navigationController).sourceType == UIImagePickerControllerSourceTypeCamera)) || (((UIImagePickerController *)navigationController).sourceType == UIImagePickerControllerSourceTypePhotoLibrary))
{
[[UIApplication sharedApplication] setStatusBarHidden:NO];
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
}
}

Can hide status bar on iphone but ipad when xcode is set to iphone

Ok. I'm going to try to ask this one more time. Hopefully, I will not inadvertently piss off the overflow police. this is not a duplicate question, if you read deeper into the question.
I have an iphone only app that I want to run on iphone and ipad. It runs fine except that when I turn off the status bar it is off on the iphone but not on the ipad.
Any suggestions?
Thanks.
I have set the keys in info.plist
UIStatusBarHidden = YES
and
UIViewControllerBasedStatusBarAppearance = NO
I have included the following code in viewdidload in my starting view controller
- (BOOL)prefersStatusBarHidden {
return YES;
}
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationSlide];
[self prefersStatusBarHidden]; // 10-9 to remove status bar
[self setNeedsStatusBarAppearanceUpdate];
The Info.Plist item should be:
UIViewControllerBasedStatusBarAppearance = YES

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

How to hide status bar in iOS 7?

I have tried setting the following in my app .plist file:
View controller-based status bar appearance: NO
And while this removes it from my initial view controller, once I go to another view and come back with my navigation controller, it comes right back and this time it does not disappear. Also, I don't see why it would matter but I have also set the status bar under simulated metrics to "None" but that doesn't seem to help. I know i am going to have the navigation bar but the status bar I need gone.
How can I get this done? Please provide a detailed answer, sample code would be great!
Update: This is NOT a duplicate solution as I have tried all other solutions and NONE seem to work for me. Most recently I tried
[[UIApplication sharedApplication]setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone];
Again, with no results. When the app initially launches a status bar is NOT present, after the user visits another view, the status bar is now present in the 2 and other views and does not go away. Even if you go back to the main view.
I have tried all of the suggestions that were posted here, unfortunately what happened here was a small mistake, in my viewDidLoad I had:
[[UIApplication sharedApplication] setStatusBarHidden:YES];
But in my viewWillAppear I had:
[[UIApplication sharedApplication] setStatusBarHidden:NO];
So this was just an issue of overriding, problem fixed now.
To hide status bar:
if [View controller-based status bar appearance: NO]: in AppDelegate.m call
[[UIApplication sharedApplication]setStatusBarHidden:YES];
else: in every view controller
- (BOOL)prefersStatusBarHidden
{
return YES;
}
Try this 2 steps:
In .Plist file of project set the property:
View controller-based status bar appearance = NO;
and
2.In all view controller's .m file in viewDidLoad method put this line of code:
[[UIApplication sharedApplication]setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone];
Use this method in the View Controller which you'd like the Status Bar hidden:
- (BOOL)prefersStatusBarHidden {
return YES;
}
This should work :
// In iOS7 this gets called and hides the status bar so the view does not go under the top iPhone
// status bar
- (BOOL)prefersStatusBarHidden {
return YES;
}
none of these work for me.
when i try this method i get the message "use of undeclared identifier preferstatusbarHidden
include - (BOOL)prefersStatusBarHidden {
return YES;
}
I don't know what to do anymore. I tried setStatusBarHidden, prefersHiddenStatusBar and still no results. Finally i have went through the below you tube link :
https://www.youtube.com/watch?v=FtpBXdMSqRQ
It worked for me.

Resources