1234567891011121314151617181920212223242526272829303132333435 |
- //
- // StatusBarBackgroundColor.swift
- // naiyoup
- //
- // Created by C Auto on 2021/6/4.
- //
- import SwiftUI
- extension UIApplication {
- class var statusBarBackgroundColor: UIColor? {
- get {
- if #available(iOS 13.0, *) {
- let statusBar = UIView(frame: UIApplication.shared.windows[0].windowScene?.statusBarManager?.statusBarFrame ?? CGRect.zero)
- return statusBar.backgroundColor
- } else {
- let statusBar: UIView = UIApplication.shared.value(forKey: "statusBar") as! UIView
- return statusBar.backgroundColor
- }
- }
- set {
- if #available(iOS 13.0, *) {
- let statusBar = UIView(frame: UIApplication.shared.windows[0].windowScene?.statusBarManager?.statusBarFrame ?? CGRect.zero)
- if statusBar.responds(to:#selector(setter: UIView.backgroundColor)) {
- statusBar.backgroundColor = newValue
- }
- UIApplication.shared.windows[0].addSubview(statusBar)
- } else {
- let statusBar: UIView = UIApplication.shared.value(forKey: "statusBar") as! UIView
- if statusBar.responds(to:#selector(setter: UIView.backgroundColor)) {
- statusBar.backgroundColor = newValue
- }
- }
- }
- }
- }
|