Question

Hi I am developing small Iphone application in which I am giving colour for my navigation bar like this

[self.navigationController.navigationBar setTranslucent:NO];    
[self.navigationController.navigationBar setBarTintColor:[UIColor redColor]];

But because of this my status bar also become of red colour. I want to change it to white. I tried in followings way but those are not working for me.

in info.plist file I set View controller-based status bar appearance = "NO"

then in application:didFinishLaunchingWithOptions: set [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];

Then in UIViewcontroller

- (UIStatusBarStyle)preferredStatusBarStyle
{
    return UIStatusBarStyleLightContent;
}

But above methods are not working for me. My navigation bar and status bar of same colour. I want to make status bar colour to white. My application is very simple having one UIView controller with one navigation controller. Am I doing some thing wrong? Need Help. Thank you .

Was it helpful?

Solution

UIStatusBarStyleLightContent tells the status bar to display light colored text, but it is still transparent. And because the navigation controller reports the position of its navigation bar to be UIBarPositionTopAttached, you see the effect of the navigation bar's color stretching beneath the status bar.

Here are two ideas how to achieve what you are looking for:

Subclass the navigation controller, implement - (UIBarPosition)positionForBar:(id<UIBarPositioning>)bar and return UIBarPositionTop. This make the navigation bar not stretch beneath the status bar, and instead the superview of the navigation bar (which is usually white), will show.

Or, better, subclass the navigation controller, add a subview of 20pt height above the navigation bar, and in viewDidLayoutSubviews, position and resize the subview correctly to orientation. Now you can give any color you'd like to this view, and it will be the color of the status bar.

Edit: Based on the comments, the positionForBar: approach may not work.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top