我曾尝试在info.plist文件中将键UIViewControllerBasedStatusBarAppearance
添加到true,然后在UINavigationController
类中添加以下代码,该代码包含几个UIViewController
类。
class HomeNavigationController: UINavigationController {
override var preferredStatusBarStyle: UIStatusBarStyle {
return .lightContent
}
}
但是,它不起作用。
[我也尝试将barStyle
的navigationBar
属性设置为.black
,但这也不起作用。
也抬头看着https://stackoverflow.com/a/58203998/9180494,但这也没有帮助。
请注意:对于未嵌入任何UIViewController
中的UINavigationController
类,如果我使用计算属性preferredStatusBarStyle
,则它可以工作。
@@ Anuranjan Bose在您的视图上尝试加载,
override func viewDidLoad() {
super.viewDidLoad()
setNeedsStatusBarAppearanceUpdate()
}