官方使用參考
http://developer.apple.com/library/ios/#documentation/uikit/reference/UIColor_Class/Reference/Reference.html
一般使用
xxx.color = [UIColor redColor];
= [UIColor blackColor];
= [UIColor greenColor];
.... 基本顏色外
比較特殊的是設定透明色 [UIColor clearColor];
還可以自定顏色如下例:(紅 綠 藍 透明度)
[UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:1.0];
[UIColor colorWithRed:0.75 green:0.75 blue:0.75 alpha:1.0], // 銀色
[UIColor colorWithRed:1.00 green:0.84 blue:0.00 alpha:1.0], // 金色
使用方法
My Color: #e7008d with RGB: R: 231, G: 0, B: 141 R: 231/255 = 0.905 G: 0/255 = 0 B: 141/255 = 0.552
透明度 1是不透明 0是完全透明 (白色的透明為黑色)
另外還有一種顏色的設定方法(分別是H指hue(色相)、S指saturation(飽和度)、L指lightness(亮度))
[UIColor colorWithHue:0.223404 saturation:0.944000 brightness:0.990291 alpha:1.0];
此處定義可參考wiki
http://zh.wikipedia.org/wiki/HSL%E5%92%8CHSV%E8%89%B2%E5%BD%A9%E7%A9%BA%E9%97%B4
參考設定
+ (UIColor *)colorWithHueDegrees:(CGFloat)hue saturation:(CGFloat)saturation brightness:(CGFloat)brightness {
return [UIColor colorWithHue:(hue/360) saturation:saturation brightness:brightness alpha:1.0];
}
+ (UIColor *)aquaColor {
return [UIColor colorWithHueDegrees:210 saturation:1.0 brightness:1.0];
}
+ (UIColor *)paleYellowColor {
return [UIColor colorWithHueDegrees:60 saturation:0.2 brightness:1.0];
}
與RGB轉換的參考程式碼可參考網址
https://github.com/alessani/ColorConverter