【问题标题】:How to change status bar colours separately for each ViewController?如何为每个视图控制器分别更改状态栏颜色?
【发布时间】:2014-04-14 14:57:02
【问题描述】:

我正在使用 iOS 7 和情节提要开发一个应用程序。我有几个视图控制器。我想要做的是根据导航栏颜色更改状态栏颜色。但是每个视图控制器都有不同颜色的导航栏。我知道我可以通过向 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 的颜色?

【问题讨论】:

  • 你在说this吗?

标签: ios7 statusbar


【解决方案1】:

将此方法添加到每个viewCONtroller

- (UIStatusBarStyle)preferredStatusBarStyle
{
  return UIStatusBarStyleDefault; // or UIStatusBarStyleLightContent
}

在每个视图控制器的 viewDidLoad 中:

[self preferredStatusBarStyle];
[self performSelector:@selector(setNeedsStatusBarAppearanceUpdate)];

同样在项目属性中,您需要将此选项设置为 YES:查看基于控制器的状态栏外观

【讨论】:

    猜你喜欢
    • 2014-02-08
    • 1970-01-01
    • 2016-05-05
    • 1970-01-01
    • 2014-11-23
    • 2018-05-24
    • 1970-01-01
    • 2017-08-16
    • 1970-01-01
    相关资源
    最近更新 更多