UIAppearance for multiple UILabels

What is considered best practice for customizing colors, fonts, etc. for different instances UILabel

through UIAppearance

?

As an example (simplified), let's say I use UILabel

for ...

  • (blue) status messages
  • (red) error messages
  • (gray) annotations
  • (black) everyone else

I create three subclasses UILabel

(which don't override anything), make sure all my instances UILabel

are of the appropriate class, and then set their appearance based on their concrete classes like this:

[[MyStatusLabel appearance] setTextColor:[UIColor blueColor]];
[[MyErrorLabel appearance] setTextColor:[UIColor redColor]];
[[MyAnnotationLabel appearance] setTextColor:[UIColor grayColor]];
[[UILabel appearance] setTextColor:[UIColor blackColor]];

      

It seems awkward to create all of these subclasses - is there a better way? Usage appearanceWhenContainedIn:

only helps when I can clearly classify the labels according to their containment hierarchy.

+3


source to share





All Articles