0

When I change the background color of the navigation bar, it is opaque like the following.

UINavigationBar.appearance().backgroundColor = .black

enter image description here

Then if I set translucent to false, I don't see any color like the following

UINavigationBar.appearance().backgroundColor = .black    
UINavigationBar.appearance().isTranslucent = true

enter image description here

Any idea on how to make a solid background color?

Megool
  • 963
  • 2
  • 8
  • 29

2 Answers2

3

Set it's barTintColor

Example:

UINavigationBar.appearance().isTranslucent = false
UINavigationBar.appearance().barTintColor = .red
staticVoidMan
  • 19,275
  • 6
  • 69
  • 98
1

You should set the barTintColor instead of the backgroundColor:

The tint color to apply to the navigation bar background.

https://developer.apple.com/documentation/uikit/uinavigationbar/1624931-bartintcolor

UINavigationBar.appearance().barTintColor = .black
Ahmad F
  • 30,560
  • 17
  • 97
  • 143