0

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!

Alex Cio
  • 6,014
  • 5
  • 44
  • 74
Lukas
  • 2,515
  • 4
  • 28
  • 37

4 Answers4

1

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

enter image description here

You just need to set preferredStatusBarStyle inside a UIViewController if you want to change the color for a single controller.

Alex Cio
  • 6,014
  • 5
  • 44
  • 74
  • 1
    This is helpful, but what if I need a statusbar color depending on controller, I just don't need the color to change on when I select the textfield..? – Lukas Feb 04 '14 at 09:34
  • Did you already change the property inside the info.plist? I also inserted a `UITextField` and tried it to but the `UIStatusBar` color is still white when selecting the textfield. Maybe you have any actions which trigger `prefferedStatusBarStyle` or you change the bar anywhere else in the code. – Alex Cio Feb 04 '14 at 09:42
  • no I don't. Your suggested solution works, unless I need a View controller-based status bar. Thanks for the help though. It works for now – Lukas Feb 04 '14 at 13:01
0

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

iPatel
  • 46,010
  • 16
  • 115
  • 137
0

Set the UIViewControllerBasedStatusBarAppearance to YES in the plist

In viewDidLoad do a [self setNeedsStatusBarAppearanceUpdate];

Add the following method:

-(UIStatusBarStyle)preferredStatusBarStyle{ 
  return UIStatusBarStyleLightContent; 
}
BalaChandra
  • 632
  • 9
  • 33
  • I don't need to hide it, I need it's text to be always white – Lukas Feb 04 '14 at 09:20
  • I am doing this already, but it still changes color to black if i select a uitextfield. – Lukas Feb 04 '14 at 09:24
  • set the preferredsattusbarstyle to NO and in appDelegate inside appDidFinishLaunching method, put [[UIView appearance] setTintColor:[UIColor whiteColor]] – BalaChandra Feb 04 '14 at 09:28
0

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?

Aish
  • 189
  • 7
  • It's a simple/standard UITextField. When I select it my status bar color changes. Never seen this before though. – Lukas Feb 04 '14 at 09:32
  • yeah same here... never heard of any such thing myself!!! anyway are you doing anything in any delegate function for the textfield?? – Aish Feb 04 '14 at 09:34
  • no I am not doing anything. If I'm doing as 亚历山大 suggested, then it doesn't change. But if I would like dynamic uistatusbar color depending on controller which I will need later then I need a different solution. – Lukas Feb 04 '14 at 09:36
  • okay i don't really know why but i just noticed that on touching the textfield the preferredStatusBarStyle gets called again... – Aish Feb 04 '14 at 09:42