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
  • 873
  • 2
  • 8
  • 28

2 Answers2

3

Set it's barTintColor

Example:

UINavigationBar.appearance().isTranslucent = false
UINavigationBar.appearance().barTintColor = .red
staticVoidMan
  • 17,682
  • 6
  • 64
  • 94
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
  • 28,447
  • 13
  • 87
  • 133