Last active
February 24, 2022 15:43
-
-
Save eonist/ffc0788c57d620aac43ae15cec4b00a9 to your computer and use it in GitHub Desktop.
Colorize status menu iOS 15
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * 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 | |
| } | |
| } |
Author
Thats true. Thanks. Updated 👍
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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!