Search code examples
iosswiftuinavigationbariphone-x

Transparent NavBar Still Showing


So I have am trying to make a transparent navBar similar to this youtube video. https://www.youtube.com/watch?v=Pjz_KU89FSY

However for some reason when I follow the steps my navBar turns out like this

enter image description here

Which continues over into the rootVC to really destroy my view and my UI. This is my viewDidLoad in the VC that controls it. I don't know what would be the problem tbh

override func viewDidLoad() {
    super.viewDidLoad()
    self.navigationController?.navigationBar.setBackgroundImage(UIImage(), for: .default)
    self.navigationController?.navigationBar.shadowImage = UIImage()
    self.navigationController?.navigationBar.isTranslucent = true
    setupVc()
}

Solution

  • This will make your Navbar transparent -

    override func viewWillAppear(_ animated: Bool) {
     self.navigationController!.navigationBar.setBackgroundImage(UIImage(), for: UIBarMetrics.default)
                    self.navigationController?.navigationBar.shadowImage = UIImage()
                    self.navigationController?.navigationBar.isTranslucent = true
                    self.navigationController!.navigationBar.backgroundColor = UIColor.clear
                }