+ (UIColor *)blackColor; // 0.0 white
+ (UIColor *)darkGrayColor; // 0.333 white
+ (UIColor *)lightGrayColor; // 0.667 white
+ (UIColor *)whiteColor; // 1.0 white
+ (UIColor *)grayColor; // 0.5 white
+ (UIColor *)redColor; // 1.0, 0.0, 0.0 RGB
+ (UIColor *)greenColor; // 0.0, 1.0, 0.0 RGB
+ (UIColor *)blueColor; // 0.0, 0.0, 1.0 RGB
+ (UIColor *)cyanColor; // 0.0, 1.0, 1.0 RGB
+ (UIColor *)yellowColor; // 1.0, 1.0, 0.0 RGB
+ (UIColor *)magentaColor; // 1.0, 0.0, 1.0 RGB
+ (UIColor *)orangeColor; // 1.0, 0.5, 0.0 RGB
+ (UIColor *)purpleColor; // 0.5, 0.0, 0.5 RGB
+ (UIColor *)brownColor; // 0.6, 0.4, 0.2 RGB
+ (UIColor *)clearColor; // 0.0 white, 0.0 alpha
使用它们呢,很简单:
UIColor *color = [UIColor redColor];
[1] 指定 RGB
+ (UIColor *)colorWithRed:(CGFloat)red green:(CGFloat)green blue:(CGFloat)blue alpha:(CGFloat)alpha;
注意的是红绿黄和透明度,都是0到1范围内的。
[2] 指定 HSB
+ (UIColor *)colorWithHue:(CGFloat)hue saturation:(CGFloat)saturation brightness:(CGFloat)brightness alpha:(CGFloat)alpha;
- hue 色调 saturation 饱和度 brightness 亮度
[3] 用图片做颜色
+ (UIColor *)colorWithPatternImage:(UIImage *)image;
应用场景:
UIImage *bgImage = [UIImage imageWithContentsOfFile:@"...ackground.png"];
UIColor *bgColor = [UIColor colorWithPatternImage:bgImage];
self.backgroundColor =bgColor;
[4] 获取当前颜色改变透明度之后的一个颜色
方法签名为:colorWithAlphaComponent
应用场景:
UIColor *color = [UIColor redColor];
UIColor *cl = [color colorWithAlphaComponent:0.5f];