Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set UINavigationBar appearance whenContainedInInstancesOf to my viewcontroller not working

I want to set white barTintColor in some viewcontroller I have set UINavigationBar.appearance().barTintColor for all default color but when I use appearance whenContainedInInstancesOf It's not change my viewcontroller

UINavigationBar.appearance(whenContainedInInstancesOf: [MyViewController.self]).barTintColor = .white

Any idea?. I tried this in my viewcontroller

self.navigationcontroller.navigationbar.barTintColor = .white

but I have to set color back to default when screen will disappear. I don't want to do like that. How can I do?

like image 595
Oniikal3 Avatar asked Feb 22 '17 20:02

Oniikal3


1 Answers

UINavigationBar is contained in a UINavigationController not UIViewController

with that said you need to create a custom UINavigationController

an empty class will do the job

class NavigationController: UINavigationController {}

then we can use it

UINavigationBar.appearance(whenContainedInInstancesOf: [NavigationController.self]).barTintColor = .white

Example can be found here

like image 103
zombie Avatar answered Oct 21 '22 04:10

zombie