iOS Custom Status Bar Background Color not displaying

后端 未结 9 1868
别那么骄傲
别那么骄傲 2020-12-16 13:30

I am trying to fill the status bar background color to orange using the following

UINavigationBar.appearance().tintColor = UIColor.orangeColor()
UINavigation         


        
9条回答
  •  被撕碎了的回忆
    2020-12-16 14:16

    Simon's answer in swift 3

    let view = UIView(frame: CGRect(x: 0.0, y: 0.0, width: UIScreen.main.bounds.size.width, height: 20.0))
    view.backgroundColor = .orange
    self.view.addSubview(view)
    

    There is one other way I know which uses private api. This has some benefits when orientation changes and keyboard is presented and view move up. I've used it and was lucky every time (app was released in the app store).

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

提交回复
热议问题