IOS Change status bar text color and background color

Identificador: 11635
Autor: Ricardo Bocchi   segunda-feira, Dia 1 de maio de 2023, às 02:56:05 horas
Revisado Por:    quarta-feira, Dia 17 de janeiro de 2018, às 23:32:24 horas
Visualização: Todos

Pontos: 0   Acessos: 7986


In Info.plist add:

<key>UIStatusBarStyle</key>
<string>UIStatusBarStyleBlackTranslucent</string>

<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>

So you can hide navigation bar and save text color.

In AppDelegate add:

func setStatusBarBackgroundColor() {    
  guard let statusBar = UIApplication.shared.value(forKeyPath: "statusBarWindow.statusBar") as? UIView else { return }    
  statusBar.backgroundColor = UIColor.init(red: 65/255.0, green: 65/255.0, blue: 66/255.0, alpha: 100.0)
}

And call this function in didFinishLaunchingWithOptions. This make status bar background color dark.


In NavigationBar Storyboard change style to Black and uncheck Translucent box, like this:



This make status bar text color white.


Result: