Change Status Bar Background Color in Swift 3

前端 未结 14 1617
挽巷
挽巷 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:49

    write this in first view controller:

    UIApplication.shared.statusBarUIView?.backgroundColor = .white
    
    
    
    
    
    
    extension UIApplication {
        var statusBarUIView: UIView? {
            if #available(iOS 13.0, *) {
                let tag = 38482458385
                if let statusBar = self.keyWindow?.viewWithTag(tag) {
                    return statusBar
                } else {
                    let statusBarView = UIView(frame: UIApplication.shared.statusBarFrame)
                    statusBarView.tag = tag
    
                    self.keyWindow?.addSubview(statusBarView)
                    return statusBarView
                }
            } else {
                if responds(to: Selector(("statusBar"))) {
                    return value(forKey: "statusBar") as? UIView
                }
            }
            return nil
        }
    }
    

提交回复
热议问题