Leif Ashley
Leif Ashley

Reputation: 275

Setting iOS Navigation background color not working correctly

I have a very specific issue. When I set the background barTintColor to my blue, it's too light. Nothing I do seems to make it 100% accurate.

So I changed the code to set the nav bar background to 100% black. Using the OS X app SIP to analyze the color, or just setting the view to black as well, it's pretty obvious the color is very dark gray, but not black.

What is making the tint color screw up? As it stands, the blue I need and what the nav bar is showing are not the same.

    navigationController?.navigationBar.setBackgroundImage(UIImage.imageFromColor(UIColor.black), for: .default)
    navigationController?.navigationBar.shadowImage = UIImage()

    navigationController?.navigationBar.barStyle = .blackOpaque
    navigationController?.navigationBar.isOpaque = true
    navigationController?.navigationBar.barTintColor = UIColor.black

Also in a blank project, fresh, same issue.

Upvotes: 1

Views: 2034

Answers (1)

Marián Černý
Marián Černý

Reputation: 15778

The key is to set isTranslucent to false.

let navigationBar = navigationController?.navigationBar
navigationBar?.barTintColor = .black
navigationBar?.isTranslucent = false

Upvotes: 7

Related Questions