We can achieve this requirement as follows:
In which UIViewController we want to clear the navigation bar. The color should be clear in this UIViewController , we need to write this code in viewDidLoad , viewWillAppear and viewWillDisappear method
In the viewDidLoad method viewDidLoad we need to write that for a better result, if we did not write, place a code fragment, then the color of the navigation bar will change after viewing.
override func viewDidLoad() { super.viewDidLoad() self.navigationController?.navigationBar.setBackgroundImage(UIImage(), for: .default) self.navigationController?.navigationBar.shadowImage = UIImage() self.navigationController?.navigationBar.isTranslucent = true } 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 self.navigationController?.navigationBar.barTintColor = UIColor.clear self.navigationController?.navigationBar.backgroundColor = UIColor.clear } override func viewWillDisappear(_ animated: Bool) { super.viewWillDisappear(animated) self.navigationController?.navigationBar.setBackgroundImage(nil, for: .default) self.navigationController?.navigationBar.shadowImage = nil self.navigationController?.navigationBar.isTranslucent = true }
When we switch to another screen (puch another UIViewController ) in the same UINavigationController , we need to set barTintColor , otherwise it will appear as black.
Sumeet mourya
source share