Change Status Bar Background Color in Swift 3

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

    With using Swift 3 and 4 you can use the code snippet on below. It finds the view from UIApplication using valueForKeyPath as set it's background color.

    guard let statusBarView = UIApplication.shared.value(forKeyPath: "statusBarWindow.statusBar") as? UIView else {
            return
        }
    statusBarView.backgroundColor = UIColor.red
    

    Objective-C

    UIView *statusBarView = [UIApplication.sharedApplication valueForKeyPath:@"statusBarWindow.statusBar"];
    if (statusBarView != nil)
    {
        statusBarView.backgroundColor = [UIColor redColor];
    }
    

提交回复
热议问题