Question

I have learned that in iOS 5, properties that are marked with UI_APPEARANCE_SELECTOR can be styled using appearance. Eg [[UINavigationBar appearance] setTintColor:....]. However, I seem not to be able to style all elements. UIButton, for instance, has no properties marked UI_APPEARANCE_SELECTOR, hence I am not able to use the above technique to style it.

My question is: How do I best style elements globally (all appearances in the application), when I cannot use appearance?

Right now I have defined some colors, fonts, shadow offsets etc. that I use many different places in my code. This allows me to change the look and behaviour of a lot of elements, but it still doesn't allow me to style all instances of a certain object with only one line of code.

Edit

In lack of better solutions I have created a number of categories with simple methods as the following:

+ (UIButton *)customLabelWithFrame:(CGRect)frame andText:(NSString *)text;

Also I have found that - in combination with the described categories - stretchable images are nice and useful.

With the above I am able to style in a global-ish manner, however I am not satisfied with the result and I still hope to find a better solution

Was it helpful?

Solution

What about standard subclassing or factory classes, as you mentioned yourself!? For buttons I'm using factory classes myself.

OTHER TIPS

I think a really nice solution could be the Android way of designing interfaces. Android relies on XML files to define the user interface. As a matter of fact, I'm working on a library that aims to give the projects I'm working on much the same capabilities. It's still a work in progress / experiment and as such really messy code (you have been warned!), but it might give you some ideas.

An example project can be downloaded here: http://dl.dropbox.com/u/6487838/WSLayoutManager.zip

Experiment a bit with the XML files by adding controls. Create custom control classes and instantiate them from the XML file, etc... It's fun stuff :)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top