How to make navigation bar transparent in iOS 7?

user1244109 picture user1244109 · Dec 2, 2013 · Viewed 47.7k times · Source

Is there a way to make the bar of a navigation controller totally transparent?

What i've tried:

[self.navigationController.navigationBar setBackgroundColor:[UIColor clearColor]];
[self.navigationController.navigationBar setBarTintColor:[UIColor clearColor]];
[self.navigationController.navigationBar setAlpha:0.0];

but the bar's appearance does not change, and stays white translucent. I'm trying to get visible the bar items, but not the bar itself. Can someone point me in the right direction? Thanks

Answer

Pradhyuman sinh picture Pradhyuman sinh · Dec 2, 2013

If anybody is wondering how to achieve this in iOS 7, here's a solution (iOS 6 compatible too)

[self.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
self.navigationBar.shadowImage = [UIImage new];
self.navigationBar.translucent = YES;

Setting translucent to YES on the navigation bar does the trick, due to a behaviour discussed in the UINavigationBar documentation. I'll report here the relevant fragment:

If you set this property to YES on a navigation bar with an opaque custom background image, the navigation bar will apply a system opacity less than 1.0 to the image.

Reference from: Make UINavigationBar transparent