I have a tabbed view with 5 tabs. Also I have a navigation bar and with the following code I change its background color:
//Change navigation colors
viewController.navigationController?.navigationBar.barTintColor = UIColor.orange
viewController.navigationController?.navigationBar.tintColor = UIColor.white
viewController.navigationController?.navigationBar.titleTextAttributes = [NSAttributedStringKey.foregroundColor: UIColor.white]
Every tab has its own view controller, so instead of putting the same code in the viewDidLoad()
method, I created a class UIHelper
that has a static method setupNavigation(viewController: UIViewController)
. So in every viewController in the : viewDidLoad()
method I just call the method
UIHelper.setupNavigation(viewController: self)
Is there an easier way to change the global color of the background of a navigation bar?
I'm using Swift 4.
Edit: Actually I have one MasterViewController
and every view controller of the tab extend it. So UIHelper.setupNavigation
is called in MasterViewController
's viewDidDLoad()
.