IPHONE程式 UIColor


UIColor是常用在iOS裡的顏色函數
它提供了一些常用的顏色 如orangeColor blackColor...
用法如下



Label.textColor=[UIColor orangeColor]

如果要取得它的rgb值
可以透過下面的方法

CGFloat R, G, B;  
UIColor *uiColor = [lblDate textColor];CGColorRef color = [uiColor CGColor]; 
int numComponents = CGColorGetNumberOfComponents(color); 
 if (numComponents == 4){ 
const CGFloat *components = CGColorGetComponents(color); 
R = components[0]; 
G = components[1]; 
B = components[2]; 
}
如果想設定UIColor的自定RGB色彩
float r,g,b; 
r=100; 
g=255; 
b=255; 
testLabel.textColor=[UIColor colorWithRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:1];


再這裡要注意的一點是
UIColor裡的RGB值是以0~1輸入 不是0~255喔

留言

這個網誌中的熱門文章

Office 2021 離線安裝封裝與KMS啟動步驟

Ollama使用心得與模型導入教學

ARC下NSMutableDictionary 無法使用retainCount