I’m new to iPhone development and are looking for at way to use color resources (like in Android). I want to apply them on text and panel backgrounds etc.
The ultimate goal is to be able to switch color resources while keeping the code and xib files intact. In this way it shall be possible to for example make several versions of the app with different text colors by just changing the rgb value in one single location.
I know it is possible to switch the image resources in this way, but havent seen anything similar with the colors.
Appreciating any help
The
UIColorclass is quite amazing.It has a lot of nice, desirable colors available out of the box. For instance:
On top of it, you can generate all sorts of nifty things with a little math and some macros. This one lets you generate colors from 8-bit hex values (i.e
0x000000for black).You can also load a
UIColorobject from an image.To use any UIColor object, you can simply do this:
Just note that the property you’re assigning has to be a UIColor property (obviously).
Edit: For what you want to do, this may be the best solution:
VJColorConstants.There are about 100 spins on how to return a constant, but I like that one. After you have that file set up, you can do this: