I am looking to hide the navigation and status bar to make it transparent. I have an image right below that I want to take up the entire space. So far, I got to hide the navigation bar but the status bar is still white- this is in the viewDidLoad()
:
self.navigationController?.setNavigationBarHidden(true, animated: true)
Also, how can I re add the back button to the the navigation bar?
Thanks!
Screen shot of my current iPhone simulator:
Edited after Mohy Gh's Code:
Swift 3: for whole app:
do this in your AppDelegate
's didFinishLaunchingWithOptions
method instead of hiding the navigation bar:
// Sets navigationBar's background to a blank/empty image
UINavigationBar.appearance().setBackgroundImage(UIImage(),
for: .default)
// Sets shadow (line below the bar) to a blank image
UINavigationBar.appearance().shadowImage = UIImage()
UINavigationBar.appearance().isTranslucent = true
EDIT : to hide navigationBar
for one specific view controller in your View controller do like this :
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
let navigationBar = self.navigationController?.navigationBar
navigationBar?.setBackgroundImage(UIImage(), for: .default)
navigationBar?.shadowImage = UIImage()
navigationBar?.isTranslucent = true
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
let navigationBar = self.navigationController?.navigationBar
navigationBar?.shadowImage = nil
navigationBar?.setBackgroundImage(nil, for: .default)
navigationBar?.isTranslucent = false
}
After making the navigationBar
transparent, you need to set your imageView
's top constraint to topLayoutGuid
= 0
if you you want to also hide statusBar
for one viewController
also put this in your desired viewController:
override var prefersStatusBarHidden: Bool {
return true
}
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