uitextfield selected changes status bar color - ios

I can't find what is wrong with UITextField (or UIStatusBar).
In my
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
I have:
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
Also in my view controller I have this:
-(UIStatusBarStyle)preferredStatusBarStyle{
return UIStatusBarStyleLightContent;
}
The color of UIStatusBar is always white as I want it to be. But whenever I select UITextField, it's color changes to black. I don't want that, and I always want it to be white.
Strange but I can't find any similar issues on the net, so I'm hoping for your help. Any help is appreciated. Thanks in advance!

If you always want the UIStatusBar with whiteColor insert the line like you did in didFinishLaunching
[[UIApplication sharedApplication]
setStatusBarStyle:UIStatusBarStyleLightContent];
and than also set a value for the statusbar inside info.plist like this
You just need to set preferredStatusBarStyle inside a UIViewController if you want to change the color for a single controller.

Just Set the UIViewControllerBasedStatusBarAppearance to YES in the plist file
and also put in viewDidLoad method [self setNeedsStatusBarAppearanceUpdate]; may be its work for you.

Set the UIViewControllerBasedStatusBarAppearance to YES in the plist
In viewDidLoad do a [self setNeedsStatusBarAppearanceUpdate];
Add the following method:
-(UIStatusBarStyle)preferredStatusBarStyle{
return UIStatusBarStyleLightContent;
}

Okay this must not happen and so i don't see a need of setting the UIStatusBarStyle again and again... could you give a little more information about your UITextField?

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.

iOS7 Navigation Bar + Status Bar Text Color

I have problems with colour of text in Status Bar. I want to make colour of text white, but keep black colour on modal views.
I have next configuration:
Storyboard with settings "Opens in 5.1" and "Project Deployment target 7.0" and "View as iOS7 and later"
UITabBarViewController
4 UINavigationControllers
Each navigation controller has custom subclass of UIViewController inside
Background colour of UINavigationBar set to dark via appearance.
View controller-based status bar appearance set to YES
My subclass of UITabBarViewController has next methods:
- (UIStatusBarStyle)preferredStatusBarStyle {
return UIStatusBarStyleLightContent;
}
- (void)viewDidLoad {
[super viewDidLoad];
[self setNeedsStatusBarAppearanceUpdate];
}
These methods are called after application started.
I also have same methods calls in my UIViewControllers subclasses:
- (UIStatusBarStyle)preferredStatusBarStyle {
return UIStatusBarStyleLightContent; // This method never called
}
- (void)viewDidLoad {
[super viewDidLoad];
[self setNeedsStatusBarAppearanceUpdate];
}
I also tried to change return value of -preferredStatusBarStyle to UIStatusBarStyleDefault (well, I know that it should paint text in black, but I tried anyway)
Same thing for setting Status Bar option to Light Content in Storyboard. Doesn't work too.
I know there are a lot of questions on SO similar to mine, but proposed solutions doesn't help in my situation.
My status bar still looks like this:
And I want to change its colour to white =/
This is a work around that I occasionally found right now after struggling with this issue for about 2 weeks.
// This is a workaround just enables white text colour in status bar in iOS7, iOS7.1
// Dont touch it until things break
// Despite this category says "draw white", colour automatically becomes black on white background w/o additional code
#interface UINavigationController (StatusBarStyle)
#end
#implementation UINavigationController (StatusBarStyle)
- (UIStatusBarStyle)preferredStatusBarStyle {
return UIStatusBarStyleLightContent;
}
#end
// Place at the bottom of your AppDelegate.m
// Magic!
I need to thank people who answered this question, but I already tried these solutions and they didn't help :( This category on UINavigationController just works.
First of all, you say that - (UIStatusBarStyle)preferredStatusBarStyle is never called in your UIViewController subclasses. It's normal. This method is called by your root view controller. In your case, it is the UITabBarViewController.
You also say that you've tried to set Status Bar option to Light Content in Storyboard. If you look closely, you should have done that in a section named Simulated metrics. So as the title suggest, modifications here are simulated...
I suggest you to try to add the key UIViewControllerBasedStatusBarAppearance in your Info.plist and to set it to YES.
You need to set this in your RootViewController :
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];

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.

iOS7 Global Tint not affecting UIToolbar

I'm finding some situations where the Global Tint I have set in the MainStoryboard isn't propagating to some sub UIViews.
An example case is simply to start with a 'MasterDetail' template application and show the UIToolbar in the MasterViewController by adding:
-(void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[self.navigationController setToolbarHidden:NO animated:YES];
}
Any items I add to the toolbar appear in the system default tint rather than my custom Global Tint.
Is anyone else having issues with this? Has anyone found a fix?
Thanks.
It doesn't seem to work on toolbars for some reason, I'm facing the same issue.
However, you can change the appearance (background not tini for some reason) of all uitoolbars from your AppDelegate, it works like charm.
Good luck, need any more help, let me know ;D
I've found a workaround.
Set the 'global tint' in code by setting the tint of the UIWindow and things work.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
[[[application windows] lastObject] setTintColor:[UIColor greenColor]];
return YES;
}
So despite the Apple documentation saying that the Global Tint setting is for the entire App, there's clearly an issue with that and you need to set it in code on the UIWindow.

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.

Resources