UIApplication.shared.keyWindow?.addSubview not working in ios13
i try many options but not find any solutions. i want every screen status bar make blue color form AppDelegate .
i try this code.
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")
}
}