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.
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.
I don't want navigation bar but I want to change status bar content to white. How to do this. Need Help. Thank you.
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 .
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.
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 onpreferredStatusBarStyle
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 implementingpreferredStatusBarStyle
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 forUIStatusBarStyleDefault
orUIStatusBarStyleLightContent
. It bases this on it'sUINavigationBar.barStyle
. The default (UIBarStyleDefault
) results in the dark foregroundUIStatusBarStyleDefault
status bar. AndUIBarStyleBlack
will give aUIStatusBarStyleLightContent
status bar.TL;DR:
If you want
UIStatusBarStyleLightContent
on aUINavigationController
use:self.navigationController.navigationBar.barStyle = UIBarStyleBlack;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.