Creating a transparent navigation bar

I'm wondering how we create a UINavigationBar that is completely transparent (alpha = 0), but the BarButton is still visible.

I would like to have an Invisible NavigationBar, but I need the BarButtonItem to be visible

Any ideas please?

+3


source to share


2 answers


Screenshot

ZIKmA.png

Swift



self.navigationController?.navigationBar.setBackgroundImage(UIImage.new(), forBarMetrics: UIBarMetrics.Default)
self.navigationController?.navigationBar.shadowImage = UIImage.new()

      

OC

[self.navigationController.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
[self.navigationController.navigationBar setShadowImage:[UIImage new]];

      

+3


source


I found a way:

Create a subclass UINavigationBar

and pass it to your navigation controller to use it.

class NavigationBar: UINavigationBar {
    // An empty implementation will make the view to be transparent
    override func drawRect(rect: CGRect) {
    }
}

      

If you are using InterfaceBuilder, you can select a navigation controller, then select its navigation bar, and then change your class accordingly.

If you do it programmatically:

let navController = UINavigationController(navigationBarClass: NavigationBar.self, toolbarClass: nil)
...

      



Result with UIBarButtonItem:

071Km.jpg

Hope it helps


Old answer:

I tried for a long time (ios6). In principle, this is possible. Make the navigation bar color UIColor.clearColor()

. Buttons should be a regular UIView inside a UIBarButton to show how you want. I think you will also need to adjust the color of the view behind the navbar.

+1


source







All Articles