2013-07-25 39 views

回答

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); 
+0

什麼是計算的方式是什麼值範圍。因爲我有更多的事情要做: - – Tafzeel

+0

1)#define kBasketEditedQuantityBackgroundColor [UIColor colorWithRed:0.95 green:0.95 blue:0.95 alpha:1] – Tafzeel

+0

#define kScanViewManualEntryButtonHighlightedBackgroundColor [UIColor colorWithRed:0.9 green:0.9 blue:0.9 alpha:1] – Tafzeel

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

+0

我應該如何設置此valies紅色:0.85綠色:0.85藍色:0.85 – Tafzeel

+0

你的顏色範圍是從0到1的權利?我在這裏使用1到255,所以轉換爲0-1範圍,同時用255分割UIColor對象。 您只需重寫下面的代碼, #define RGBCOLOR(r,g,b)[UIColor colorWithRed:r green :g blue:b alpha:1] – imalvare

+0

以及0.85的值是什麼? – Tafzeel

2

實施例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

+0

喜, 我已經嘗試使用: - 的#define kBasketEditedQuantityBorderColor RGBCOLOR(0.85,0.85, 0.85)[UIColor colorWithRed:0.85 green:0.85 blue:0.85 alpha:1] 但是它給了我一個錯誤... :( – Tafzeel

+0

RGBCOLOR是一個宏,重新定義宏你需要聲明RGBCOLOR之前使用。 – Elto

+0

實施例1: 的#define RGBCOLOR(R,G,B)[的UIColor colorWithRed:R t綠:藍ģ:乙阿爾法:1]; 的#define kBasketEditedQuantityBorderColor RGBCOLOR(0.85,0.85,0.85); 用途:按鈕。 backgroundColor = kBasketEditedQuantityBorderColor; – Elto

相關問題