iOS 7中基于不同ViewControllers设置灯光状态栏文字颜色的正确方法 [英] The correct way to set a light status bar text color in iOS 7 based on different ViewControllers

查看:17
本文介绍了iOS 7中基于不同ViewControllers设置灯光状态栏文字颜色的正确方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要让嵌入在 UINavigationController 中的特定 ViewController 具有浅色状态栏文本颜色(但其他 ViewController 的行为不同).我知道至少有 3 种方法,但在我的情况下没有一种方法有效.

I need to let a specific ViewController embedded in an UINavigationController to have light status bar text color (but other ViewControllers to behave differently). I am aware of at least 3 methods, none of which however work in my case.

  1. 如何更改状态栏文本iOS 7中的颜色,方法主要是:

  • 在plist中设置UIViewControllerBasedStatusBarAppearanceYES
  • 在 viewDidLoad 中执行 [self setNeedsStatusBarAppearanceUpdate];
  • 添加如下方法:

  • Set the UIViewControllerBasedStatusBarAppearance to YES in the plist
  • In viewDidLoad do a [self setNeedsStatusBarAppearanceUpdate];
  • Add the following method:

- (UIStatusBarStyle)preferredStatusBarStyle{ 
      return UIStatusBarStyleLightContent; 
  }

在 iOS 7.0.3 上运行,此方法对我不起作用,因为即使在我正确实现了所有 3 个步骤之后,也永远不会调用 preferredStatusBarStyle.

Running on iOS 7.0.3, this method does not work for me, since even after I have implemented all 3 steps correctly, preferredStatusBarStyle is never called.

UIStatusBarStyle PreferredStatusBarStyle 在 iOS 7 上不起作用,方法主要是:

将您的 navigationBarbarStyle 设置为 UIBarStyleBlackTranslucent 将提供白色状态栏文本(即 UIStatusBarStyleLightContent),而 UIBarStyleDefault 将给出黑色状态栏文本(即 UIStatusBarStyleDefault).

Setting your navigationBar’s barStyle to UIBarStyleBlackTranslucent will give white status bar text (ie. UIStatusBarStyleLightContent), and UIBarStyleDefault will give black status bar text (ie. UIStatusBarStyleDefault).

此方法在 iPhone 上有效,但在 iPad 上无效.

This method works fair and square on iPhone, but not on iPad.

在plist中设置UIViewControllerBasedStatusBarAppearanceNO,并使用

Setting the UIViewControllerBasedStatusBarAppearance to NO in the plist, and use

[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];

这显然不适用于这种情况,因为我只需要为两个 ViewController 指定不同的状态栏颜色.

This clearly doesn't apply in this case, since I need to only specify different status bar colors for two of the ViewControllers.

感谢大家的帮助!

推荐答案

对于遇到 UINavigationController 问题的人,我可以建议创建自定义 UINavigationController 并实现 preferredStatusBarStyle 就这样:

For people having this problem with a UINavigationController I can recommend creating a custom UINavigationController and implementing the preferredStatusBarStyle on it like this:

- (UIStatusBarStyle)preferredStatusBarStyle
{
    return [self.topViewController preferredStatusBarStyle];
}

这样状态栏样式将是顶视图控制器的样式.现在您可以随意实现视图控制器的 preferredStatusBarStyle.

That way the statusbar style will be that of the top view controller. Now you can implement the view controller's preferredStatusBarStyle anyway you like.

这篇关于iOS 7中基于不同ViewControllers设置灯光状态栏文字颜色的正确方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆