Question

Hi I am developing small IOS application in which I am using simple one window with navigation controller. What I want to do is change status bar colour to white. For that I did following things.

[self.navigationController.navigationBar setBarTintColor:[UIColor redColor]];
[self.navigationController.navigationBar setBarStyle:UIBarStyleBlackTranslucent];
[self.navigationController.navigationBar setTintColor:[UIColor whiteColor]];

It works fine.enter image description here

But now I don't want navigation bar and I hide it self.navigationController.navigationBarHidden = YES;

It removes navigation bar but it is not applying that white colour theme to my status bar. It again turn to black.

enter image description here

I don't want navigation bar but I want to change status bar content to white. How to do this. Need Help. Thank you.

Was it helpful?

Solution

Use UIStatusBarStyleLightContent.

[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];

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

Also, change the UIViewControllerBasedStatusBarAppearance in your PLIST file to NO.

NOTE: This question has been asked before. Please research a little more for questions like this.

OTHER TIPS

you can set a UIView with color on status bar, check this:

UIView *temporaryStatusBar = [[UIView alloc] initWithFrame:[[UIApplication sharedApplication] statusBarFrame]];
temporaryStatusBar.backgroundColor = [UIColor greenColor];
[self.window addSubview:temporaryStatusBar];

This can be done simply . Please check out these StackOverflow links to see the best fit for you. My advice is to look more . The status bar is made by default as transparent in iOS 7 so we need to apply these procedures to make it look like it was before iOS 7.

Status bar and navigation bar issue in IOS7

How to set Status bar background color iOS 7

You should use:

self.navigationController.navigationBar.hidden = YES;

instead of:

self.navigationController.navigationBarHidden = YES;

NavigationBar hidden behavior can be strange if UIViewController is child viewController of UINavigationController.

Bellow comments are research from @Tyson and @ing0 in this answer: For anyone using a UINavigationController:

The UINavigationController does not forward on preferredStatusBarStyle calls to its child view controllers. Instead it manages its own state - as it should, it is drawing at the top of the screen where the status bar lives and so should be responsible for it. Therefor implementing preferredStatusBarStyle in your VCs within a nav controller will do nothing - they will never be called.

The trick is what the UINavigationController uses to decide what to return for UIStatusBarStyleDefault or UIStatusBarStyleLightContent. It bases this on it's UINavigationBar.barStyle. The default (UIBarStyleDefault) results in the dark foreground UIStatusBarStyleDefault status bar. And UIBarStyleBlack will give a UIStatusBarStyleLightContent status bar.

TL;DR:

If you want UIStatusBarStyleLightContent on a UINavigationController use:

self.navigationController.navigationBar.barStyle = UIBarStyleBlack;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top