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?
Screenshot
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]];
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:
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.