我想仅使用MACRO函数RGBCOLOR(R,G,B)重写颜色常量值
我的代码是:
#define kBasketEditedQuantityBorderColor [UIColor colorWithRed:0.85 green:0.85 blue:0.85 alpha:1]
答案 0 :(得分:6)
您可以直接在objective-C中使用C宏功能
#define RGBCOLOR(r, g, b) [UIColor colorWithRed:r/225.0f green:g/225.0f blue:b/225.0f alpha:1]
RGBCOLOR(25.0f, 25.0f, 114.0f)
我希望这会产生你的目标。
例如: [yourView setBackgroundColor:RGBCOLOR(25.0f,25.0f,114.0f)];
http://www.codeproject.com/Articles/8376/Function-like-Macros-vs-Inline-Functions
答案 1 :(得分:2)
示例1:
#define RGBCOLOR(R,G,B) [UIColor colorWithRed:R/255.2f green:G/255.2f blue:B/255.2f alpha:1];
-Usage:RGBCOLOR(243,243,243);
示例2:
#define RGBCOLOR(R,G,B) [UIColor colorWithRed:R green:G blue:B alpha:1];
-Usage:RGBCOLOR(0.95,0.95,0.95);
两个示例具有相同的结果,取决于您要使用的值范围0-1或0-255
答案 2 :(得分:0)
这可以帮到你
#define HEXCOLOR(c) [UIColor colorWithRed:((c>>24)&0xFF)/255.0 green:((c>>16)&0xFF)/255.0 blue:((c>>8)&0xFF)/255.0 alpha:((c)&0xFF)/255.0];
// usage:
UIColor* c = HEXCOLOR(0xff00ffff);