iOS 5: Can you override UIAppearance customisations in specific classes?

心已入冬 提交于 2019-12-04 16:29:42

问题


I'm building an app with many view controllers: I have a UITabBarController which holds 4 UINavigationController. I want all the nav bars to be my custom color, say blue, which I achieve by doing this in my app delegate:

[[UINavigationBar appearance] setTintColor:[UIColor blueColor]];

But I also have one special view controller which has a map, and for this view controller I want to override the blue navbar set using UIAppearance to make it the black opaque style. I've tried by calling this inside viewDidLoad:

self.navigationController.navigationBar.barStyle = UIBarStyleBlack;
self.navigationController.navigationBar.translucent = YES;

But nothing happens. Can this be done or do I have to abandon UIAppearance and set the properties on navigationBar manually for each view controller?


回答1:


The way you are doing it is supposed to work, but it doesn't. This does work though:

Swift 4

UINavigationBar.appearance(whenContainedInInstancesOf: [YourOtherVC.self]).tintColor = .black

Objective-C

[[UINavigationBar appearanceWhenContainedIn:[YourOtherVC class], nil] setTintColor:[UIColor blackColor]];



回答2:


Move your changes to viewWillAppear: instead of viewDidLoad: and it should work.




回答3:


For that you would do:

id specialNavBarAppearance = [UINavigationBar appearanceWhenContainedIn:[SpecialViewController class], nil];

[specialNavBarAppearance setBarStyle:UIBarStyleBlack];
[specialNavBarAppearance setTranslucent:YES];


来源:https://stackoverflow.com/questions/8459821/ios-5-can-you-override-uiappearance-customisations-in-specific-classes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!