clocksmith clocksmith - 6 months ago 11
iOS Question

What is the iOS equivalent of Android's colors.xml

In android there is an XML file as

that lets you organize all of your colors used in your app. Like this:

<?xml version="1.0" encoding="utf-8"?>
<color name="red">#e60012</color>
<color name="blue">#33b5e5</color>

Is there something like this in iOS? If not, what is the best way to organize colors that are used throughout the app?

I would like to ultimately be able to replace things like
[UIColor greenColor]
[MyColor greenColor]


I have not come across a default file like this. You could create your own custom .plist file which holds the values and you load that when the app starts. Another option is to create a Category for UIColor which has a bunch of class methods returning the colors you want.

You could create something that looks like this:


@interface UIColor (CustomColors)

    + (UIColor *)customColor1;
    + (UIColor *)customColor2;



#import "UIColor+CustomColors.h"

@implementation UIColor (CustomColors)

    + (UIColor *)customColor1 {
        return [UIColor colorWithRed:1.0f green:0.5f blue:0.5f alpha:1.0f];
    + (UIColor *)customColor2 {
        return [UIColor colorWithRed:1.0f green:0.5f blue:1.0f alpha:1.0f];


Then where you set the background you could have something like this:


#import "UIColor+CustomColors.h"


view.backgroundColor = [UIColor customColor1];