ios - 重写变量后状态栏样式没有改变?

标签 ios swift

我将以下代码添加到我的 UITableViewController 类中:

override var preferredStatusBarStyle: UIStatusBarStyle {
    return .lightContent
}

但在我重新运行应用程序后,没有任何变化,状态栏仍然是黑色的:

输出: Error: status bar still dark style

项目导航器: Project Navigator

界面生成器: Interface Builder

RestaurantTableViewController 中的代码: enter image description here

我想要它是白色的,我应该添加什么?

最佳答案

你应该打电话

self.setNeedsStatusBarAppearanceUpdate()

然后状态栏样式会更新

此外,您应该在 info.plist 中设置

<key>UIViewControllerBasedStatusBarAppearance</key>
<true/>

编辑:

我认为您的 UITableViewController 不是 rootViewController。如果上述解决方案不起作用,请尝试为您的 rootViewController 设置 preferredStatusBarStyleUINavigationController 根据您的屏幕截图看起来像根 Controller

关于ios - 重写变量后状态栏样式没有改变?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43702964/

相关文章:

ios - Swift 3 中的 Hashids.org 不工作

iOS聊天应用程序设计

ios - SWIFT tableView 行对选择没有反应

swift - 在什么情况下,我应该在 swift 中使用 _ 作为参数

ios - 在快速滚动 collectionview 时,第一行数据在最后一行重复

ios - 在使用 CocoaPods 编译期间包含目录作为搜索路径

ios - 在 SwiftUI 中平滑更改 View 位置

ios - swift 从 ALAsset 获取图像

ios - AWSCognitoIdentityMultiFactorAuthentication 永远不会返回

swift - 从 NSTimeInterval 转换为天