The design of my application consists of multiple viewControllers which all have different styling applied to them. The following code is used in every viewController to style the viewController:
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
self.title = "PROFILE"
self.navigationController?.view.backgroundColor = .white
self.navigationController?.navigationBar.tintColor = self.view.tintColor
navigationController?.navigationBar.barStyle = .default
tabBarController?.tabBar.isTranslucent = false
tabBarController?.tabBar.backgroundColor = .white
tabBarController?.tabBar.tintColor = .black
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
self.navigationController?.navigationBar.tintColor = .white
self.navigationController?.view.backgroundColor = UIColor.clear
self.navigationController?.navigationBar.barStyle = .blackTranslucent
self.navigationController?.navigationBar.shadowImage = UIImage()
}
Some properties change per VC, for example the backgroundColor of the VC. This code is copy pasted in every VC I make with small changes, which causes a lot of duplicate code etc. Is there a design pattern which allows me to create the styling of every VC more conveniently?