The correct way to set a light status bar text color in iOS 7 based on different ViewControllers(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.
如何更改状态栏文本iOS 7中的颜色,方法主要是:
- 在plist中设置
UIViewControllerBasedStatusBarAppearance为YES - 在 viewDidLoad 中执行
[self setNeedsStatusBarAppearanceUpdate]; 添加如下方法:
- Set the
UIViewControllerBasedStatusBarAppearancetoYESin 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.
在plist中设置UIViewControllerBasedStatusBarAppearance为NO,并使用
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设置灯光状态栏文字颜色的正确方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:iOS 7中基于不同ViewControllers设置灯光状态栏文字颜色的正确方法
基础教程推荐
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
- iOS4 创建后台定时器 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
