设置图片的渐变色

//设置颜色数组

 UIColor *startColor = [UIColor clearColor];

 UIColor *EndColor = UIColorFromRGB(0x272727);

 //创建CAGradientLayer实例

CAGradientLayer *gradient = [CAGradientLayer layer];

//设置颜色

gradient.colors = [NSArray arrayWithObjects:

                           (id)startColor.CGColor,

                           (id)EndColor.CGColor,

                           nil];

//设置渐变的frame

CGRect colorFrame = self.contentView.bounds;

colorFrame.origin.y = colorFrame.size.height / 2;

colorFrame.size.height = colorFrame.size.height / 2;

gradient.frame = colorFrame;

//添加到当前视图

 [imageView.layer insertSublayer:gradient atIndex:0];


你可能感兴趣的:(设置图片的渐变色)