首页 > 解决方案 > XCode11,iOS如何设置statusBar背景色

问题描述

如何更改 Swift 以设置 StatusBar 背景颜色?

在此代码预期工作之前。

func setStatusBarStyle(_ style: UIStatusBarStyle, backgroundColor:UIColor = .clear) {
     if let statusBar = UIApplication.shared.value(forKey: "statusBar") as? UIView {
         statusBar.backgroundColor = backgroundColor
         statusBar.setValue(style == .lightContent ? UIColor.white : .black, forKey: "foregroundColor")
     }
}

现在使用 Xcode11 我得到编译致命错误:

*** 由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因:“在 UIApplication 上调用 -statusBar 或 -statusBarWindow 的应用程序:必须更改此代码,因为不再有状态栏或状态栏窗口。在窗口场景中使用 statusBarManager 对象。

任何想法将不胜感激

标签: iosswiftxcode

解决方案


推荐阅读