Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I make my navigation bar transparent in swift?

I want to make my navigation controller like this. My main view should continue to the top. enter image description here

But when I am trying implement it I get this result: enter image description here

How can I handle this problem. I want to implement something like in first image. Can anybody help? Thanks

like image 789
berkt Avatar asked Dec 14 '22 08:12

berkt


2 Answers

I use this in my Apps to make my navigationBar transparent (if the navigationBar is in a UINavigationController):

self.navigationController?.navigationBar.setBackgroundImage(UIImage(), forBarMetrics: .Default)
self.navigationController?.navigationBar.shadowImage = UIImage()
self.navigationController?.navigationBar.translucent = true

Now you can still add buttons and a title to your navigationBar.

EDIT: Swift 3 (Thanks to DrBreakalot)

self.navigationController?.navigationBar.setBackgroundImage(‌​UIImage(), for: .default) 
self.navigationController?.navigationBar.shadowImage = UIImage()
self.navigationController?.navigationBar.isTranslucent = true
like image 59
Jan Doornbos Avatar answered Jan 22 '23 20:01

Jan Doornbos


Since you already have your title and button in your view, it looks like you want to hide the navigation bar rather than make it transparent. If you don't want the navigation bar on any of your screens you can uncheck 'Shows Navigation Bar' in the Storyboard.

Or, if you only want to hide the navigation bar on certain screens, you can set it in viewDidLoad()

navigationController?.setNavigationBarHidden(true, animated: true)
like image 42
Allanah Fowler Avatar answered Jan 22 '23 21:01

Allanah Fowler