我以前有以下代码,但是升级到iOS 13之后,出现以下错误:
UIApplication.shared.statusBarView?.backgroundColor = UIColor(red: 94/225, green: 64/255, blue:204/255, alpha: 1.0)
在UIApplication上名为-statusBar或-statusBarWindow的应用程序:必须更改此代码,因为不再有状态栏或状态栏窗口。请在窗口场景上使用statusBarManager对象。'
现在如何设置状态栏的背景色?
由于statusBar
始终是private
属性,因此在iOS 13
中已对其进行了重新设计,因此他们引入了StatusBarManager,它没有公开statusBar
的公共api。
要修复崩溃和其他自定义设置,请添加以下内容,并从此customStatusBar
中添加您自己的answer:>
extension UIApplication { var statusBarUIView: UIView? { if #available(iOS 13.0, *) { let tag = 38482458 if let statusBar = self.keyWindow?.viewWithTag(tag) { return statusBar } else { let statusBarView = UIView(frame: UIApplication.shared.statusBarFrame) statusBarView.tag = tag self.keyWindow?.addSubview(statusBarView) return statusBarView } } else { if responds(to: Selector(("statusBar"))) { return value(forKey: "statusBar") as? UIView } } return nil }
}