我正在使用iOS 7和故事板开发应用程序。我有几个视图控制器。我想要做的是根据导航栏颜色更改状态栏颜色。但每个viewcontroller都有一个不同的颜色导航栏。我知道我可以通过向info.plist添加一个标志来更改状态栏颜色,代码如下:
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7)
{
self.window.clipsToBounds = YES;
[[UIApplication sharedApplication] setStatusBarStyle: UIStatusBarStyleBlackOpaque];
UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
if(orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight)
{
self.window.frame = CGRectMake(20, 0,self.window.frame.size.width-20,self.window.frame.size.height);
self.window.bounds = CGRectMake(20, 0, self.window.frame.size.width, self.window.frame.size.height);
} else
{
self.window.frame = CGRectMake(0,20,self.window.frame.size.width,self.window.frame.size.height-20);
self.window.bounds = CGRectMake(0, 20, self.window.frame.size.width, self.window.frame.size.height);
}
}
但是如何更改每个ViewController
的颜色?
答案 0 :(得分:0)
将此方法添加到每个viewCOntroller
- (UIStatusBarStyle)preferredStatusBarStyle
{
return UIStatusBarStyleDefault; // or UIStatusBarStyleLightContent
}
在每个视图控制器的viewDidLoad中:
[self preferredStatusBarStyle];
[self performSelector:@selector(setNeedsStatusBarAppearanceUpdate)];
同样在项目属性中,您需要将此选项设置为YES:查看基于控制器的状态栏外观