cdub cdub - 3 months ago 12
Objective-C Question

Using a UIColor category in iOS 7 and Objective c

I have a UIColor+MyLayout.m file such as:

@implementation UIColor (Layout)

- (UIColor *) textBackground
{
UIColor *lightGreen = [UIColor colorWithRed:0.0f/255.0f green:178.0f/255.0f blue:238.0f/255.0f alpha:1.0f];

return lightGreen;
}

@end


I have added the .h file to my viewcontroller.m, but how do I call this into a UIColor?

UIColor *myColor = ?

Answer

Would be better if you do the following:

@implementation UIColor (Layout)

+ (UIColor *) textBackground {
    UIColor *lightGreen = [UIColor colorWithRed:0.0f/255.0f green:178.0f/255.0f        blue:238.0f/255.0f alpha:1.0f];
    return lightGreen;
}

@end

And then just call it UIColor *myColor = [UIColor textBackground];