I am inside a UINavigationController. The UINavigationController has 3 view controllers. The first 2 are tableViewControllers, the last one is a regular view controller, with a PageViewController embedded.
I am using the following code in the third view controller in the stack to make the UINavigationBar clear:
navigationController?.navigationBar.shadowImage = UIImage()
navigationController?.navigationBar.setBackgroundImage(UIImage(), forBarMetrics: UIBarMetrics.Default)
I put this code in the third view controller in the stack. That is the view controller with a UIPageViewController embedded. But the nav bar is black. However, when I pop the third controller off the stack and go back to the second, a UITableViewController, the navigation bar there is clear.
I have looked at numerous other questions, here: How to make completely transparent navigation bar in iOS 7 and here: Transparent UINavigationBar in Swift but nothing works.
what am I doing wrong? the 2 lines of code above are the only ones I'm using, but I have also tried the suggestions in the links above, and nothing works. Here is a photo of the black nav bar:
What worked for me, when I was struggling with the same problem, was to subclass the NavigationController, and use this in the viewDidLoad
method:
self.navigationBar.translucent = YES;
self.navigationBar.shadowImage = [UIImage new];
[self.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
another reason might be that your ViewController doesn't extended under your UINavigationBar
, and thats why you see the black part, try setting this in the viewDidLoad
of your ViewContorller
self.edgesForExtendedLayout = UIRectEdgeTop;
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