Am newbie to ios and I found this solution on making the UINavigationBar Transparent. Where in my project files can I put this code
[self.navigationBar setBackgroundImage:[UIImage new]
forBarMetrics:UIBarMetricsDefault];
self.navigationBar.shadowImage = [UIImage new];
self.navigationBar.translucent = YES;
So that it is applied in my entire project where navigation controller is being used.
You need to do three things to make a navigation bar transparent. Set background image to non-nil empty image ( UIImage() ). Set shadow image to non-nil empty image ( UIImage() ). Set isTranslucent to true .
Translucent or partially transparent is when the colour can be seen but the background behind the object is also slightly visible through it. For this we use. background-color: #FFFFFF; opacity: 0.5; filter: alpha(opacity=50);
Put in your viewDidLoad
function of your rootViewController this code:
[self.navigationController.navigationBar setBackgroundImage:[UIImage new]
forBarMetrics:UIBarMetricsDefault];
self.navigationController.navigationBar.shadowImage = [UIImage new];
self.navigationController.navigationBar.translucent = YES;
self.navigationController.view.backgroundColor = [UIColor clearColor];
if let navigationBar = navigationController?.navigationBar {
navigationBar.setBackgroundImage(UIImage(), forBarMetrics: .Default)
navigationBar.shadowImage = UIImage()
navigationBar.translucent = true
navigationController?.view.backgroundColor = .clearColor()
}
if let navigationBar = navigationController?.navigationBar {
navigationBar.setBackgroundImage(UIImage(), for: .default)
navigationBar.shadowImage = UIImage()
navigationBar.isTranslucent = true
navigationController?.view?.backgroundColor = .clear
}
This works for sure! Transparent UINavigationBar.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With