ios 的colorWithRed:green:blue:alpha:

这个函数的值的类型均为CGFloat.所以使用该函数自定义颜色时,要用到如下方式进行转换:

UIColor *myUIColor = [UIColor colorWithRed: (135./255.0 ) green: (50.0/255.0) blue: (66.0/255.0) alpha:1.0];
CGColorRef CGColorValue = [myUIColor CGColor];
const CGFloat *componentColors = CGColorGetComponents(CGColorValue);

 

that gives you component elements that you can reference like so

red is componentColors[0];
green is componentColors[1];
blue is componentColors[2];
alpha is componentColors[3];

if you were to use those colors to set the RGB fil, its like so

CGContextSetRGBFillColor(myContext, componentColors[0],componentColors[1],componentColors[2],componentColors[3]);

你可能感兴趣的:(IOS)