18

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

user1244109
  • 2,166
  • 2
  • 26
  • 24
  • 2
    This is answered here: http://stackoverflow.com/questions/18969248/how-to-draw-a-transparent-uitoolbar-or-uinavigationbar-in-ios7 – gagarwal Dec 02 '13 at 02:03

2 Answers2

68

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

Community
  • 1
  • 1
Pradhyuman sinh
  • 3,936
  • 1
  • 23
  • 38
  • I tried this, it works but now the back button is not visible any solution for that. – nuteron Mar 21 '14 at 15:59
  • @nuteron Try with this may be it will help you: self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:nil action:nil]; – Pradhyuman sinh Mar 24 '14 at 04:25
  • @Pradhyumansinh Thank you for your solution. After setting bar to translucent, I want to revert to default background. What should I do? http://stackoverflow.com/questions/24298375/revert-navigation-bars-background-image-to-default – Han Pengbo Jun 19 '14 at 05:11
22

You can make Navigation Bar Transparent with following code


[self.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
[self.navigationBar setShadowImage:[UIImage new]];
[self.navigationBar setTranslucent:YES];
vikingosegundo
  • 52,040
  • 14
  • 137
  • 178
Haresh Ghatala
  • 1,996
  • 17
  • 25
  • Can we set the alpha of the navigation bar if we do like this? – Q.u.a.n.g L. Apr 25 '14 at 02:09
  • ya definitely, you can do this by `[self.navigationBar setAlpha:YourValue];` – Haresh Ghatala Apr 25 '14 at 04:37
  • 1
    @HareshGhatala Thank you for your solution. After setting bar to translucent, I want to revert to default background. What should I do? stackoverflow.com/questions/24298375/… – nimingzhe2008 5 mins ago edit – Han Pengbo Jun 19 '14 at 05:16