iOS Status Bar changing color to match navigation

2019-04-02 13:22发布

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:

enter image description here

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

3条回答
2楼-- · 2019-04-02 13:39

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.

查看更多
霸刀☆藐视天下
3楼-- · 2019-04-02 13:40

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

查看更多
我欲成王,谁敢阻挡
4楼-- · 2019-04-02 13:59

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];
查看更多
登录 后发表回答