我想重寫僅使用MACRO功能RGBCOLOR(R,G,B)對於[UIColor colorWithRed:0.85 green:0.85 blue:0.85 alpha:1],MACRO函數RGBCOLOR(R,G,B)是什麼?
我的代碼是顏色常數的值:
#define kBasketEditedQuantityBorderColor [UIColor colorWithRed:0.85 green:0.85 blue:0.85 alpha:1]
我想重寫僅使用MACRO功能RGBCOLOR(R,G,B)對於[UIColor colorWithRed:0.85 green:0.85 blue:0.85 alpha:1],MACRO函數RGBCOLOR(R,G,B)是什麼?
我的代碼是顏色常數的值:
#define kBasketEditedQuantityBorderColor [UIColor colorWithRed:0.85 green:0.85 blue:0.85 alpha:1]
這可以幫助你
#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);
你可以直接在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:
#define RGBCOLOR(R,G,B) [UIColor colorWithRed:R/255.2f green:G/255.2f blue:B/255.2f alpha:1];
-usage:RGBCOLOR(243243243);
實施例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
喜, 我已經嘗試使用: - 的#define kBasketEditedQuantityBorderColor RGBCOLOR(0.85,0.85, 0.85)[UIColor colorWithRed:0.85 green:0.85 blue:0.85 alpha:1] 但是它給了我一個錯誤... :( – Tafzeel
RGBCOLOR是一個宏,重新定義宏你需要聲明RGBCOLOR之前使用。 – Elto
實施例1: 的#define RGBCOLOR(R,G,B)[的UIColor colorWithRed:R t綠:藍ģ:乙阿爾法:1]; 的#define kBasketEditedQuantityBorderColor RGBCOLOR(0.85,0.85,0.85); 用途:按鈕。 backgroundColor = kBasketEditedQuantityBorderColor; – Elto
什麼是計算的方式是什麼值範圍。因爲我有更多的事情要做: - – Tafzeel
1)#define kBasketEditedQuantityBackgroundColor [UIColor colorWithRed:0.95 green:0.95 blue:0.95 alpha:1] – Tafzeel
#define kScanViewManualEntryButtonHighlightedBackgroundColor [UIColor colorWithRed:0.9 green:0.9 blue:0.9 alpha:1] – Tafzeel