I need to setUp a NavigationBar color for a single ViewController. What Im currently doing is setting up the nav color on viewDidLoad() and resetting it to .clear (so it uses whatever color is set on the newly pushed VC) on viewWillDissappear. While this sorta works, it is not fast enough as the .clear color is not applied until the pushing animation is over, resulting in like half a second of the navigationBar color being visible until it is finally resetted to .clear.
Current code looks like this:
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
navigationController?.navigationBar.setNavBarColor(color: .red)
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
navigationController?.navigationBar.setNavBarColor(color: .clear)
}
func setNavBarColor(color: UIColor) {
let appearance: UINavigationBarAppearance = UINavigationBarAppearance()
appearance.configureWithTransparentBackground()
appearance.backgroundColor = color
self.standardAppearance = appearance
self.scrollEdgeAppearance = appearance
}
This works but isnt fast enough as the changes take effect only after the pushing animation ends. Any tip?
Set your navigation bar with my extension:
call it in viewWillAppear or viewDidLoad and change your background colors, in your case set background to clear... How to use:
In your case, call configureNavigationBar func in viewWillAppear of start controller, call configureNavigationBar in viewDidLoad of destination controller.. ES: In SceneDelegate set your start controller under scene function:
this is StartController:
This is DestinationController:
the result: