5

I use this line of code to change navigation bar background:

    [[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"image.png"] forBarMetrics:UIBarMetricsDefault];

in iOS6, it works, but in iOS5, background of the status bar is changed too, as shown in this image: enter image description here

how does this happen. Thanks in advance.

One more thing, I just want to change the color of UINavigationBar, so I used this code:

[[UINavigationBar appearance] setTintColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"image.png"]]];

It works in iOS6 quite well, but does not in iOS5. What is the reason?

eonil
  • 83,476
  • 81
  • 317
  • 516
zhijie
  • 642
  • 11
  • 17
  • Did you check your `[[UIApplication sharedApplication] statusBarStyle]` is set to `UIStatusBarStyleBlackTranslucent`? – eonil Dec 05 '12 at 11:33
  • thanks, Eonil,your advice works. but is there anyway to remain the status bar style as it be, because this seems change the status bar style even after this app quits ? – zhijie Dec 05 '12 at 11:45
  • 1
    Refer here: http://stackoverflow.com/questions/4393348/translucent-status-bars-iphone-ipad-ipod-touch – eonil Dec 05 '12 at 11:48
  • thanks, it seems developers can change status bar at will. hope this won't offend our users. is it in the user experience guide? I have not finish reading that yet. – zhijie Dec 05 '12 at 11:54
  • It's case by case. Usually changing color or hiding it (for case of immersive app) is fine, but modifying content of the status bar is usually not acceptable. – eonil Dec 05 '12 at 12:02

1 Answers1

6

You can use this one to set your status bar

 [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackTranslucent animated:YES];

So status bar colour will be black and font colour will be white..

Denny
  • 25
  • 5
chandan
  • 2,453
  • 23
  • 31