ios - 在 XCode 8.2/Swift 3.0 中更改状态栏样式(No "View controller-based status bar appearance")

标签 ios swift statusbar

我正在尝试修改状态栏的外观(将文本设为白色/将样式设置为“浅色”)。我设法通过将此添加到我的 AppDelegate.swift 文件来设置背景颜色:

let statWindow = UIApplication.shared.value(forKey:"statusBarWindow") as! UIView
let statusBar = statWindow.subviews[0] as UIView
statusBar.backgroundColor = UIColor(red: 0/255.0, green: 0/255.0, blue: 0/255.0, alpha: 1.0)

但是,当我去更改状态栏文本的样式时,即使在“常规”>“部署信息”>“状态栏样式”下进行更改(将其更改为“Light”)也不起作用。

我也尝试通过 Info.plist 修改状态栏,但是没有“基于 View Controller 的状态栏外观”字段(见第二张图片)。此外,在状态栏样式选项下没有“浅色”样式选项(见下图):

状态栏样式选项: ScreenShot

没有 View Controller 状态栏字段: ScreenShot

最佳答案

您错过的步骤是 Info.plist。

打开您应用的 info.plist 文件并将 UIViewControllerBasedStatusBarAppearance 设置为 NO(如下所示)。

Screenshot

注意:如果此 key 不存在,可以通过以下方式添加:

1) 将鼠标悬停在现有条目上以显示添加/删除图标:

enter image description here

2) 单击加号图标添加新的键/值对:

enter image description here

3) 将 UIViewControllerBasedStatusBarAppearance 粘贴到关键字段并将其值设置为 NO。请注意,当取消选择时,键将更改为 View controller-based status... 但它是同一件事:

enter image description here enter image description here

关于ios - 在 XCode 8.2/Swift 3.0 中更改状态栏样式(No "View controller-based status bar appearance"),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41824225/

相关文章:

ios - 将 base64 字符串解码为 UIImage 时出错

swift - 如何从游戏场景 swift 中获取不同文件中的 SKNode

ios - preferredStatusBarStyle 不工作

iOS 6+ : UITableViewController embedded into Navigation Controller shows table's first section header under status bar when Navigation Bar is hidden

java - 在 Java 中创建 NSStatusItem/Menubar 应用程序

ios - 在谷歌路径中的坐标之间插入点的最佳方法是什么?这种方法正确吗?

iphone - 如何将服务器连接到 Xmmp 服务器

iphone - 带有时区的日期时间对象在 Objective C 应用程序开发中不起作用

iphone - 用图像掩盖图像?

ios - 如何使用目标使用相同的代码库启动多个应用程序?