Skip to content

Instantly share code, notes, and snippets.

@eonist
Last active February 24, 2022 15:43
Show Gist options
  • Select an option

  • Save eonist/ffc0788c57d620aac43ae15cec4b00a9 to your computer and use it in GitHub Desktop.

Select an option

Save eonist/ffc0788c57d620aac43ae15cec4b00a9 to your computer and use it in GitHub Desktop.
Colorize status menu iOS 15
/**
* Window and statusbar (iOS 15 etc)
*/
extension UIApplication {
/**
* - Note: Key Scene can be found by doing keyWin.windowScene
*/
public var keyWin: UIWindow? {
UIApplication
.shared
.connectedScenes
.flatMap { ($0 as? UIWindowScene)?.windows ?? [] }
.first { $0.isKeyWindow }
}
/**
* - Note: Must be named statusBarRect, as statusBarFrame is occupied by a native call that is deprecated
*/
public var statusBarRect: CGRect? {
keyWin?.windowScene?.statusBarManager?.statusBarFrame
}
var statusBarUIView: UIView? {
if #available(iOS 13.0, *) {
let tag = 38_482_458_385
if let statusBar = keyWin?.viewWithTag(tag) {
return statusBar
} else {
let v = UIView()
v.backgroundColor = .red
v.frame = statusBarRect ?? .zero
v.tag = tag
keyWin?.addSubview(v)
return v
}
} else {
if responds(to: Selector(("statusBar"))) {
return value(forKey: "statusBar") as? UIView
}
}
return nil
}
}
@ArseniLaputska
Copy link

ArseniLaputska commented Feb 23, 2022

Hi! Thanks for sharing you thoughts about this case. Just for a little tip this variable statusBarUIVIew need to put inside extension. Then we can call this from viewDidLoad and its works good. Thanks mate!

@eonist
Copy link
Author

eonist commented Feb 24, 2022

Thats true. Thanks. Updated 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment