//初始化CAGradientlayer对象,使它的大小为UIView的大小
CAGradientLayer*gradientLayer = [CAGradientLayer layer];
gradientLayer.frame= rect;
//将CAGradientlayer对象添加在我们要设置背景色的视图的layer层
//设置渐变区域的起始和终止位置(范围为0-1)
gradientLayer.startPoint=CGPointMake(0,1);
gradientLayer.endPoint=CGPointMake(1,1);
//设置颜色数组
gradientLayer.colors=@[(__bridgeid)fristColor.CGColor,
(__bridgeid)endColor.CGColor];
//设置颜色分割点(范围:0-1)
gradientLayer.locations=@[@(0.0f),@(1.0f)];
returngradientLayer;
网友评论