我将以下代码添加到我的 UITableViewController 类中:
override var preferredStatusBarStyle: UIStatusBarStyle {
return .lightContent
}
但在我重新运行应用程序后,没有任何变化,状态栏仍然是黑色的:
RestaurantTableViewController 中的代码:
我想要它是白色的,我应该添加什么?
最佳答案
你应该打电话
self.setNeedsStatusBarAppearanceUpdate()
然后状态栏样式会更新
此外,您应该在 info.plist 中设置
<key>UIViewControllerBasedStatusBarAppearance</key>
<true/>
编辑:
我认为您的 UITableViewController
不是 rootViewController。如果上述解决方案不起作用,请尝试为您的 rootViewController 设置 preferredStatusBarStyle
。 UINavigationController
根据您的屏幕截图看起来像根 Controller
关于ios - 重写变量后状态栏样式没有改变?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43702964/