我试图在特定的UIStatusBar中更改UIViewController的色调。
这里是我的代码:
override var preferredStatusBarStyle: UIStatusBarStyle {
return .lightContent
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(true)
self.setNeedsStatusBarAppearanceUpdate()
}什么都没发生。
发布于 2018-11-24 12:28:42
在UINavigationController上,preferredStatusBarStyle不被调用,因为它的topViewController比self更好。因此,要让preferredStatusBarStyle调用UINavigationController,您需要更改它的childViewControllerForStatusBarStyle。
要为一个UINavigationController执行此操作:
class MyRootNavigationController: UINavigationController {
override var preferredStatusBarStyle: UIStatusBarStyle {
return .lightContent
}
override var childViewControllerForStatusBarStyle: UIViewController? {
return nil
}
}发布于 2018-11-24 12:32:09
您可以向UINavigationController添加一个扩展
extension UINavigationController {
open override var childForStatusBarStyle: UIViewController? {
return visibleViewController
}
}然后,对于您想要的轻量级状态栏(白色时间、图标等)的视图控制器,然后重写preferredStatusBarStyle。
override var preferredStatusBarStyle: UIStatusBarStyle {
return UIStatusBarStyle.lightContent
}对于一个黑暗的状态酒吧,你什么都不用做。
发布于 2018-12-07 07:09:34
您可能需要在info.plist中添加“基于视图控制器的状态栏外观”,其值为"YES“。
https://stackoverflow.com/questions/53457475
复制相似问题