iOS状态栏更改颜色,以自己匹配导航栏

我在我的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; 

这将使您的状态栏再次变黑。

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