开发者

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

开发者 https://www.devze.com 2023-02-05 09:07 出处:网络
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

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

精彩评论

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