UIStatusBarStyle 在 Swift 中不起作用 [英] UIStatusBarStyle not working in Swift

查看:29
本文介绍了UIStatusBarStyle 在 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

文档要说的就是 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
}

我错过了什么?

推荐答案

您有两个选择.

如果你想继续手动设置状态栏的样式,继续做你正在做的事情,但你需要将以下键添加到你的 info.plist 文件中,值为 NO.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆