开发者

creating a color that will be shared by Mac and iOS code

I want to create my colors in a consistent way across both the Mac and iOS versions of my app. According to CGColor.h, the function

CGColorCreate(CGColorSpaceRef space, const CGFloat components[]) 

is available on both platforms. But it se开发者_开发知识库ems annoyingly heavyweight. Is there an easier way?

Thanks.


Personally, I'd probably just go with:

#if TARGET_OS_IPHONE
#define HSBA(h,s,b,a) [UIColor colorWithHue: h saturation: s brightness: b alpha: a]
#else
#define HSBA(h,s,b,a) [NSColor colorWithHue: h saturation: s brightness: b alpha: a]
#endif

id tangerine = HSBA(0.084,1.0,1.0,1.0);

Another choice is:

#if TARGET_OS_IPHONE
#define MYCOLOR UIColor
#else
#define MYCOLOR NSColor
#endif

MYCOLOR *tangerine = [MYCOLOR colorWithHue:0.084 saturation:1.0 brightness:1.0 alpha:1.0];

Yet another choice would be creating your own function. :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜