Re: global UIColor
Re: global UIColor
- Subject: Re: global UIColor
- From: Mike Abdullah <email@hidden>
- Date: Sun, 22 Mar 2009 15:36:14 +0000
This is almost exactly what I'd do. But for a performance boost, amend
to:
+ (UIColor *)myColor
{
static UIColor *result;
if (!result)
{
result = [[UIColor colorWithRed:0.11 green:0.11 blue:0.11 alpha:1.0]
retain];
}
return result;
}
On 22 Mar 2009, at 14:43, Dave DeLong wrote:
While it might be considered overkill, the way I would do this is to
make a UIColor category:
@interface UIColor (MyColor)
+ (UIColor *) myColor;
@end
@implementation UIColor (MyColor)
+ (UIColor *) myColor {
return [UIColor colorWithRed:0.11 green:0.11 blue:0.11 alpha:1.0];
}
@end
Make sure the @interface bit is #imported wherever you need it, and
now you can get your color by doing:
UIColor * myColor = [UIColor myColor];
Categories are one of the reasons I fell in love with this
language. =)
HTH,
Dave
On Mar 22, 2009, at 8:38 AM, Harry G wrote:
I'm setting up my constants in my app, and have come across a
problem. I wish to have a standard UIColor to use for all titles in
my app but I get the error "error: initializer element is not
constant" and for obvious reasons , but my question is: How am I
'supposed' to implement a single global UIColor?
#import "XXConstants.h"
@implementation XXConstants
const NSString *const1 = @"MyString";
const int const2 = 111;
UIColor * const3 = [UIColor colorWithRed:.11 green:.11 blue:.11
alpha:1]; //the offender
@end
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden