我需要让嵌入在 UINavigationController
中的特定 ViewController 具有浅色状态栏文本颜色(但其他 ViewController
的行为不同).我知道至少有 3 种方法,但在我的情况下没有一种方法有效.
I need to let a specific ViewController embedded in an UINavigationController
to have light status bar text color (but other ViewController
s to behave differently). I am aware of at least 3 methods, none of which however work in my case.
如何更改状态栏文本iOS 7中的颜色,方法主要是:
UIViewControllerBasedStatusBarAppearance
为YES
[self setNeedsStatusBarAppearanceUpdate];
添加如下方法:
UIViewControllerBasedStatusBarAppearance
to YES
in the plist[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 ViewController
s.
感谢大家的帮助!
对于遇到 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设置灯光状态栏文字颜色的正确方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!