I can't set UINavigationBar's barTintColor to clearColor successfully
Asked Answered
M

2

6

There's a strange iOS 7 thing about UINavigationBar. If you try to set it's barTintColor property to [UIColor clearColor] or any color with a alpha = 0, it totally ignores that value. So for instance, if you write:

[[navigationBar setBarTintColor:[UIColor clearColor]];

It doesn't respect the "clear" part at all. Same result with colorWithRed:green:blue:alpha.

But the most interesting part is, if you set translucent property to NO, then it will take the color you specified BUT with alpha 1. So if I specify colorWithRed:1 green:0 blue:0 alpha:0 it will be set to pure red with alpha as 1.

How can I achieve it? Is there any possible solution to make it a completely invisible barTintColor, although it requires hacky methods?

Modernistic answered 2/11, 2013 at 0:11 Comment(0)
N
5

If you want a clear navigation controller try setting the background image of the navigation controller to use a clear PNG file (1x1 transparent, no color).

Nahshu answered 2/11, 2013 at 0:22 Comment(2)
Great! It works! One detail is that you don't even need to create an image like that. Instead, set the backgroundImage to [UIImage new] through the pertinent method and it'll work.Modernistic
+1 Thanks. I managed to get it working but I had to set translucent to YES. Without this, the bar was black.Metzger
E
4

This works for me

navigationBar.translucent = true
navigationBar.setBackgroundImage(UIImage(), forBarMetrics: .Default)
Edwards answered 26/2, 2016 at 14:47 Comment(1)
Works! Swift 5 will looks like: navigationBar.isTranslucent = true navigationBar.setBackgroundImage(UIImage(), for: .default)Pepin

© 2022 - 2024 — McMap. All rights reserved.