-2

When I use this:

    UINavigationBar.appearance().backgroundColor = UIColor(named: "brown")

I get a nav bar that has the correct brown and it is translucent.

nav bar with translucent brown

But I don't want it to be translucent, I just want it to be my brown color. So, I add another line of code to change the appearance to turn off the translucency, and instead of getting a solid brown, it just gives me the default white.

    UINavigationBar.appearance().backgroundColor = UIColor(named: "brown")
    UINavigationBar.appearance().isTranslucent = false

nav bar all white

What am I doing wrong?

Kenny Wyland
  • 20,844
  • 26
  • 117
  • 229

2 Answers2

1

You're barking up the wrong tree completely. Leave isTranslucent alone! Do not set any navigation bar properties directly! Use UINavigationBarAppearance to perform your configuration. For example:

let app = UINavigationBarAppearance()
app.configureWithOpaqueBackground()
app.backgroundColor = .brown
UINavigationBar.appearance().standardAppearance = app
UINavigationBar.appearance().scrollEdgeAppearance = app
aheze
  • 24,434
  • 8
  • 68
  • 125
matt
  • 515,959
  • 87
  • 875
  • 1,141
0

You can apply:

UINavigationBar.appearance().barTintColor = UIColor(named: "brown")

I think changing only backgroundColor is not enough in this case.