繁体   English   中英

iOS状态栏更改颜色以单独匹配导航栏

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

我的AppDelegate中有一个带有UITableView的RootViewController的UINavigationController。 启动时,状态栏将其颜色更改为导航栏的颜色。 当我将导航栏颜色设置为橙色时,状态栏如下所示:

在此处输入图片说明

我的导航栏似乎移到了顶部一点。 导航控制器似乎无法识别状态栏。 如何解决此问题?

我在应用程序中唯一拥有的是一个AppDelegate和一个空的RootViewController。 我的application:didFinishLaunchingWithOptions是:

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;

我的RootViewController的IB文件只有一个空视图。

没什么不寻常的。 我对iOS很有经验,这就是我每次都这样做的方式。 我不知道这次有什么不同。

有人可以告诉我吗? 谢谢

将您的状态栏样式UIStatusBarStyleBlackOpaqueUIStatusBarStyleBlackOpaque ,您将获得一个实心的黑色栏。

为此,请在应用程序的实例上使用setStatusBarStyle:animated: ::

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

在iOS 6.0中,状态栏会更改颜色以匹配导航栏(如果有的话)。 这是预期的行为。

添加此代码:

[UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleBlackOpaque;

这将使状态栏再次变黑。

您应该更改导航栏的颜色添加它。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM