-
// Some convenience methods to create colors. These colors will be as calibrated as possible.
// These colors are cached.
+ (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];
当然了:
+ (UIColor *)colorWithRed:(CGFloat)red green:(CGFloat)green blue:(CGFloat)blue alpha:(CGFloat)alpha;
这个也很容易理解,注意的是红绿黄和透明度,都是0到1范围内的。
当然了:
+ (UIColor *)colorWithHue:(CGFloat)hue saturation:(CGFloat)saturation brightness:(CGFloat)brightness alpha:(CGFloat)alpha;
意思应该比较清楚吧:
其实还是用的图片。。。很多人在理解这个函数名时,容易有歧义。
+ (UIColor *)colorWithPatternImage:(UIImage *)image;
应用场景:
UIImage *bgImage = [UIImageimageWithContentsOfFile:@"...\background.png"];
UIColor *bgColor = [UIColor colorWithPatternImage:bgImage];
self.backgroundColor =bgColor;
方法签名为:
colorWithAlphaComponent
应用场景:
UIColor *color = [UIColor redColor];
UIColor *cl = [color colorWithAlphaComponent:0.5f];
-
转载请注明来自:http://blog.csdn.net/prevention