在导航控制器中时,将忽略视图控制器的首选状态栏样式
我正在编写具有多个视图的iOS应用.我将应用程序设置为使用基于ViewController的状态栏样式,这使我可以使用以下代码
I'm writing an iOS App with multiple views. I've set the App to use ViewController-based status bar style, which allows me to use the following code
override var preferredStatusBarStyle: UIStatusBarStyle {
return .lightContent
}
效果与预期一样.
但是随后我将视图嵌入导航控制器中,并将BarButtonItem与showSegue连接起来.从那以后,视图的ViewController切换为忽略样式设置,并显示默认的黑色状态栏.
But then I've embedded the views in a navigation controller and connected a BarButtonItem with a showSegue. Since then the ViewController of the view switched to ignores the style settings and shows the default black status bar.
当您位于不会被调用的导航控制器中时.导航控制器的preferredStatusBarStyle将被调用.尝试将其与您的代码一起使用:
When you're in a navigation controller that will not get called. The navigation controller's preferredStatusBarStyle will be called. Try this along with your code:
extension UINavigationController {
open override var preferredStatusBarStyle: UIStatusBarStyle {
return topViewController?.preferredStatusBarStyle ?? .default
}
}