quano quano - 1 year ago 136
iOS Question

Make UINavigationBar transparent

How do you make a UINavigationBar transparent? Though I want its bar items to remain visible.

Answer Source

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

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

In swift

self.navigationBar.setBackgroundImage(UIImage(), forBarMetrics: .Default)
self.navigationBar.shadowImage = UIImage()
self.navigationBar.translucent = true


Setting translucent to YES on the navigation bar does the trick, due to a behavior 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.