I'm using UIAppearance to customize all UIBarButtonItem, with:
[[UIBarButtonItem appearance] setTintColor:[UIColor purpleColor]];
Apart from the poor color choice, it works great.
Now, I want some buttons with a specific style. So I create a new class, let's call it YellowDoneBarButtonItem
.
I want to customize it too, so I add:
[[YellowDoneBarButtonItem appearance] setTintColor:[UIColor yellowColor]];
Unfortunately, the last call to ... appearance] setTintColor:
wins, and all buttons, subclass or not, adopt the last specified color.
I can't use appearanceWhenContainedIn:
because sometimes, I might have the two different button styles in the same navigation bar.
Is there a way to use UIAppearance
more selectively than an all or nothing?
The doc says:
In any given view hierarchy, the outermost appearance proxy wins. Specificity (depth of the chain) is the tie-breaker. In other words, the containment statement in appearanceWhenContainedIn: is treated as a partial ordering. Given a concrete ordering (actual subview hierarchy), UIKit selects the partial ordering that is the first unique match when reading the actual hierarchy from the window down.
Any trick to bend this fact to what's needed here?