1

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!

Rengers
  • 14,911
  • 1
  • 36
  • 54
Sukh
  • 1,278
  • 11
  • 19

3 Answers3

7

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

RajeshKumar R
  • 15,445
  • 2
  • 38
  • 70
0

Better you must avoid the navigation bar. Hide the navigation bar in the navigation controller and user custom view in your view controller to avoid this issue.

0

Swift 5:: Calling below in AppDelegate's didFinishLaunchingWithOptions function does the trick (This will be applied to your all navigationBars though, don't forget to switch your view controllers)

let navBarAppearance = UINavigationBarAppearance()
navBarAppearance.configureWithTransparentBackground()
            
navigationController?.navigationBar.standardAppearance = navBarAppearance
navigationController?.navigationBar.scrollEdgeAppearance = navBarAppearance

alidinc
  • 51
  • 6