iOS: How to define some default objects to be used anywhere?

There are many places in my app that needs to set the UIColor. I want to define the color somewhere that I can reuse it without writing the same line again, it's hard to keep track and maintain.

UIColor *myColor = [UIColor colorWithRed:0.1 green:0.3 blue:0.7 alpha:1];

I tried to make it like

#define myColor = [UIColor colorWithRed:0.1 green:0.3 blue:0.7 alpha:1];

and reuse myColor but it doesn't work. :/



For your define, you could write:

#define myColor [UIColor colorWithRed:0.1 green:0.3 blue:0.7 alpha:1]

and where you use myColor, it'll be replaced outright with [UIColor colorWithRed:0.1 green:0.3 blue:0.7 alpha:1].

Alternatively, you could write a category on UIColor that provides a method that returns your colour.


@interface UIColor (MyColors)

+ (UIColor *)myAwesomeColor;


@implementation UIColor (MyColors)

+ (UIColor *)myAwesomeColor
    return [UIColor colorWithRed:0.1 green:0.3 blue:0.7 alpha:1];


You would then use this like [UIColor myAwesomeColor] wherever you need it, just like you do with [UIColor blackColor].

Need Your Help

Handling layout event in Vaadin

java vaadin vaadin7

I have a issue with Vaadin. It seems as the layout click event listener consumes my right clicks as well as left clicks.

Embed bold face markup in Haddock documentation

haskell haddock

Is there a way to get bold faced text when documenting Haskell source code with haddock markup? There is / / for emphasis, but nothing obvious for strong. I'm hoping for