iOS Status bar turned black by Photo Framework - ios

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

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.

Status bar becomes black

I have a status bar with style UIStatusBarStyleLightContent(white text). But when the Application is sent to background, in the task manager, the status bar is shown with black text and it stays black until the application is fully in foreground again (it is black through the whole go to front animation).
I observed this behavior only in iPhone 6 and iPhone 6+ (simulator and actual device). It shows up white (as expected) on iPhone 4s, 5 and 5s (tested on simulator)
I just found a solution. It is a bug which gets solved if the proper splash screens are defined.
Try following steps, should be working in iOS 8+ as well.
1) Add property View controller-based status bar appearance => NO in Info.plist.
2) Add following piece of code in AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
[self.window setBackgroundColor:[UIColor redColor]]; // Change color as per need.
return YES;
}
3) Override method in ViewController or you can consider overriding in ParentViewController of all ViewController if you have such Inheritance hierarchy. Otherwise you have to override this method in every ViewController.
- (UIStatusBarStyle) preferredStatusBarStyle {
return UIStatusBarStyleLightContent;
}

status bar became visible after dismiss UIImagePicker in iOS 8

getting strange issue in iOS 8
i have made made
View controller-based status bar appearance is NO in info.plist file
implemented following methods
-(void)navigationController:(UINavigationController *)navigationController
willShowViewController:(UIViewController *)viewController
animated:(BOOL)animated
{
[[UIApplication sharedApplication] setStatusBarHidden:YES];
}
-(BOOL)prefersStatusBarHidden;
{
return YES;
}
the problem is when i navigate to photo gallery at time status bar is hidden , but after dismissing it , status bar became visible for entire app .
Thanks.
You need to hide status bar in view will apear of the class in which you are calling imagepicker using below code.
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:NO];
From Plist
Status bar initially hidden Select YES
ViewController Based Status bar Set to NO.
it will work the trick.

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"

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