transparent navigation bar ios

Peter Pik picture Peter Pik · Sep 15, 2014 · Viewed 162.9k times · Source

I'm creating an app and i've browsed on the internet and i'm wondering how they make this transparent navigationBar like this:

enter image description here

I've added following like in my appdelegate:

UINavigationBar.appearance().translucent = true

but this just makes it look like following:

enter image description here

How can i make the navigationBar transparent like first image

Answer

Vidhyanand picture Vidhyanand · Sep 15, 2014

You can apply Navigation Bar Image like below for Translucent.

Objective-C:

[self.navigationController.navigationBar setBackgroundImage:[UIImage new]
                     forBarMetrics:UIBarMetricsDefault]; //UIImageNamed:@"transparent.png"
self.navigationController.navigationBar.shadowImage = [UIImage new];////UIImageNamed:@"transparent.png"
self.navigationController.navigationBar.translucent = YES;
self.navigationController.view.backgroundColor = [UIColor clearColor];

Swift 3:

self.navigationController?.navigationBar.setBackgroundImage(UIImage(), for: .default) //UIImage.init(named: "transparent.png")
self.navigationController?.navigationBar.shadowImage = UIImage()
self.navigationController?.navigationBar.isTranslucent = true
self.navigationController?.view.backgroundColor = .clear