Change Status Bar Background Color in Swift 3

前端 未结 14 1605
挽巷
挽巷 2020-11-28 04:21

In XCode 7.3.x ill changed the background Color for my StatusBar with:

func setStatusBarBackgroundColor(color: UIColor) {
guard  let statusBar = UIApplicatio         


        
14条回答
  •  隐瞒了意图╮
    2020-11-28 04:56

    extension UIApplication {
        var statusBarView: UIView? {
            if responds(to: Selector(("statusBar"))) {
                return value(forKey: "statusBar") as? UIView
            }
            return nil
        }
    }
    
    UIApplication.shared.statusBarView?.backgroundColor = .red
    

    Update for iOS 13

    App called -statusBar or -statusBarWindow on UIApplication: this code must be changed as there's no longer a status bar or status bar window. Use the statusBarManager object on the window scene instead.

    Refer to How to change the status bar background color and text color on iOS 13?

提交回复
热议问题