问题描述
我需要让嵌入在 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设置灯光状态栏文字颜色的正确方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!


大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)