UIStatusBarStyle无法在Swift中运行 [英] UIStatusBarStyle not working in Swift
问题描述
我正在尝试将我的Swift应用中的状态栏颜色更改为白色,但是我正在撞墙。我有3个ViewControllers,每个都嵌入在NavigationController中(这可能是问题吗?我已经尝试将代码放在NavigationController类中。)我在AppDelegate的didFinishLaunchingWithOptions中尝试了以下两段代码.swift文件,但都没有工作。
I'm trying to change the Status Bar color in my Swift app to white, but am hitting a brick wall. I have 3 ViewControllers that are each embedded in a NavigationController (could that be the issue? I've already tried to place the code in the NavigationController class.) I've tried both of the following pieces of code in the didFinishLaunchingWithOptions of my AppDelegate.swift file but neither worked.
application.statusBarStyle = .LightContent
和
UIApplication.sharedApplication().statusBarStyle = .LightContent
Docs所说的一切都是UIBarButtonStyle是一个Int并给了我这个枚举完全没有帮助我的片段。
All that the Docs have to say about it is that UIBarButtonStyle is an Int and gave me this enum snippet which didn't help me at all with implimentation.
enum UIStatusBarStyle : Int {
case Default
case LightContent
case BlackOpaque
}
我缺少什么?
推荐答案
您有两种选择。
如果你想要c ontinue手动设置状态栏的样式,继续执行您正在执行的操作,但您需要将以下键添加到info.plist文件中,其值为否
。
If you want to continue manually setting the style of the status bar, continue doing what you're doing, but you'll need to add the following key to your info.plist file with a value of NO
.
查看基于控制器的状态栏外观
View controller-based status bar appearance
或者,如果要继续使用基于视图控制器的状态栏外观,而不是设置应用程序的statusBarStyle,请覆盖每个视图控制器中的 preferredStatusBarStyle
属性您要指定状态栏样式。
Or, if you want to continue to use view controller based status bar appearance, instead of setting the application's statusBarStyle, override the preferredStatusBarStyle
property in each view controller for which you'd like to specify a status bar style.
Swift 3
override var preferredStatusBarStyle: UIStatusBarStyle {
return .lightContent
}
Swift 2
override func preferredStatusBarStyle() -> UIStatusBarStyle {
return UIStatusBarStyle.LightContent
}
这篇关于UIStatusBarStyle无法在Swift中运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!