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

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

问题描述

我需要让嵌入在 UINavigationController 中的特定ViewController具有灯状态栏文本颜色(但其他 ViewController s表现不同)。我知道至少有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中将 UIViewControllerBasedStatusBarAppearance 设置为 YES

  • 在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上不起作用,方法主要是:

设置 navigationBar barStyle 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.

设置 UIViewControllerBasedStatusBarAppearance 在plist中 NO ,并使用

Setting the UIViewControllerBasedStatusBarAppearance to NO in the plist, and use

[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];

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

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天全站免登陆