创建渐变颜色

来源:互联网 发布:aws azure 阿里云 编辑:程序博客网 时间:2024/05/17 07:39

CGGradientRef TableBackgroundGradient()

{

static CGGradientRef layoutGradient = NULL;

if (!layoutGradient)

{

UIColor *contentColorTop = [UIColor colorWithRed:0.90 green:0.92 blue:0.95 alpha:1.0];

UIColor *contentColorBottom = [UIColor colorWithRed:0.70 green:0.72 blue:0.75 alpha:1.0];


CGColorSpaceRef colorspace = CGColorSpaceCreateDeviceRGB();

CGFloat backgroundColorComponents[3][4];

memcpy(

backgroundColorComponents[0],

CGColorGetComponents(contentColorTop.CGColor),

sizeof(CGFloat) * 4);

memcpy(

backgroundColorComponents[1],

CGColorGetComponents(contentColorBottom.CGColor),

sizeof(CGFloat) * 4);

const CGFloat endpointLocations[2] = {0.0, 1.0};

layoutGradient =

CGGradientCreateWithColorComponents(

colorspace,

(const CGFloat *)backgroundColorComponents,

endpointLocations,

2);

CFRelease(colorspace);

}

return layoutGradient;

}

原创粉丝点击