iOS Status Bar changing color to match navigation bar on its own

佐手、 提交于 2020-01-01 07:20:21

问题


I have a UINavigationController in my AppDelegate with a RootViewController that has a UITableView. On startup, the status bar changes its color to the color of the navigation bar. When I colored my navigation bar to orange, this is what the status bar is looking like:

It seems that my navigation bar is shifted to the top a little bit. It appears that the navigation controller does not recognize the status bar. How can I fix this issue?

The only thing I have in my app is an AppDelegate and an empty RootViewController. My application:didFinishLaunchingWithOptions is:

self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
RootViewController *rootViewController = [[RootViewController alloc] initWithNibName:@"RootViewController" bundle:nil];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:rootViewController];
[navigationController.navigationBar setTintColor:[UIColor orangeColor]];
self.window.rootViewController = navigationController;
[self.window makeKeyAndVisible];
return YES;

My IB file for RootViewController just has an empty view.

Nothing unusual. I'm pretty experienced with iOS and that's how I've been doing it every single time. I have no idea what is different this time.

Could someone please advise me? Thanks


回答1:


Set your status-bar-style towards UIStatusBarStyleBlackOpaque and you should get a solid black bar.

To do that, use setStatusBarStyle:animated: on your applications' instance:

[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackOpaque 
                                            animated:NO];



回答2:


In iOS 6.0 the status bar changes color to match the navigation bar, if there is one. This is expected behavior.




回答3:


Add this code:

[UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleBlackOpaque;

This will make your status bar black again.

You should add it after changing the color of your navigation bar.



来源:https://stackoverflow.com/questions/15712567/ios-status-bar-changing-color-to-match-navigation-bar-on-its-own

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!