I am wondering how do we create a UINavigationBar that is totally transparent (alpha = 0) but the BarButton Item is still visible.
I would like to have an Invisible NavigationBar but I need the BarButtonItem to be visible.
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 of UINavigationBar
and give it to the 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 then you can select the navigation controller, then select its navigation bar, then change its class appropriately.
If you are doing it programatically:
let navController = UINavigationController(navigationBarClass: NavigationBar.self, toolbarClass: nil)
...
Result with an UIBarButtonItem:
Hope it helps
Old Answer:
I tried long time ago (ios6). Basically it is possible. Make the color of navigation bar to be UIColor.clearColor()
. Buttons will need to be custom UIViews inside the UIBarButton so the show the way you want. I think you will need to adjust the color of the view behind the navigation bar too.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.