Search code examples
iosswiftuinavigationbar

How to remove navigation bar colour clear in swift4?


I want to clear color of navigation bar. In my ViewController there is a background image on that, when i remove color of navigation barTintColor, navigationController.view.background and navigation background image then simulator shows me :- enter image description here

I have been trying alots of codes but there is no solution found. I want navigation Bar like that:- enter image description here

with clear navigation bar color. Is there any solution, let me know? Thanks!


Solution

  • You can make the navigation bar transparent in viewWillAppear and remove transparency in viewWillDisappear as follows

    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        self.navigationController?.navigationBar.setBackgroundImage(UIImage(), for: .default)
        self.navigationController?.navigationBar.shadowImage = UIImage()
        self.navigationController?.navigationBar.isTranslucent = true
    }
    override func viewWillDisappear(_ animated: Bool) {
        super.viewWillDisappear(animated)
        self.navigationController?.navigationBar.setBackgroundImage(nil, for: .default)
        self.navigationController?.navigationBar.shadowImage = nil
        self.navigationController?.navigationBar.isTranslucent = false
    }
    

    The background image and the back button will be visible

    enter image description here