Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIAppearance's "when not contained in"

I am currently spinning a complex web of UIAppearance modifiers*, and have come across a problem.

My usage of FlatUIKit's custom UIBarButton appearance protocol is causing MFMailComposerViewController to complain and stop working.

Therefore, instead of using UIAppearance's whenContainedIn method to specify classes that cause modification to occur, is there a way to exclude certain classes, i.e. a "when not contained in"?

*I am talking about the UIAppearance protocol that is used to predefine object appearance settings in the app's delegate.

like image 548
Sarreph Avatar asked Oct 16 '13 16:10

Sarreph


1 Answers

You can use appearanceWhenContainedIn: to specify nil modification, which will give the default appearance:

[[UIBarButton appearance] setBarTintColor:[UIColor redColor]];
[[UIBarButton appearanceWhenContainedIn:[MFMailComposerViewController class], nil] setBarTintColor:nil];

As of iOS 9 SDK, there is also

[[UIBarButton appearance] setBarTintColor:[UIColor redColor]];
[[UIBarButton appearanceWhenContainedInInstancesOfClasses:@[[MFMailComposerViewController class]] setBarTintColor:nil];

Which can be used Swift-2 like so:

UIBarButton.appearance().barTintColor = UIColor.redColor()
UIBarButton.appearanceWhenContainedInInstancesOfClasses([MFMailComposerViewController.self]).barTintColor = nil
like image 186
Léo Natan Avatar answered Sep 22 '22 22:09

Léo Natan