UIApplication.shared.keyWindow?.addSubview 在 ios13 中不起作用
我尝试了很多选择,但没有找到任何解决方案。我希望每个屏幕状态栏都以 AppDelegate 的形式呈现蓝色。
我试试这段代码。
if #available(iOS 13.0, *) {
/* let window = UIApplication.shared.windows.filter {$0.isKeyWindow}.first
// Reference - https://stackoverflow.com/a/57899013/7316675
let statusBar = UIView(frame: window?.windowScene?.statusBarManager?.statusBarFrame ?? CGRect.zero)
statusBar.backgroundColor = publicMethod().hexStringToUIColor(hex: "#033d6f")
window?.addSubview(statusBar)
*/
let statusBar = UIView()
statusBar.frame = UIApplication.shared.statusBarFrame
statusBar.backgroundColor = .blue
UIApplication.shared.statusBarStyle = .lightContent
UIApplication.shared.keyWindow?.addSubview(statusBar)
} else {
let statusBar: UIView = UIApplication.shared.value(forKey: "statusBar") as! UIView
if statusBar.responds(to:#selector(setter: UIView.backgroundColor)) {
//statusBar.backgroundColor = UIColor.darkGray
statusBar.backgroundColor = publicMethod().hexStringToUIColor(hex: "#033d6f")
}
}