iOS设置渐变色

CAGradientLayer *layer1 = [self setChangColorWithView:_View andColorStart:[UIColor colorWithRed:255/255.0 green:178/255.0 blue:0/255.0 alpha:1.0] andEndColor:[UIColor colorWithRed:251/255.0 green:226/255.0 blue:0/255.0 alpha:1.0]];
_View.layer.sublayers = nil;
[_View.layer addSublayer:layer1];

-(CAGradientLayer *)setChangColorWithView:(UIView *)view andColorStart:(UIColor *)startColor andEndColor:(UIColor *)endColor{
CAGradientLayer *gradLayer = [CAGradientLayer layer];
gradLayer.frame = view.bounds;
gradLayer.colors = @[(__bridge id)startColor.CGColor,(__bridge id)endColor.CGColor];
gradLayer.startPoint = CGPointMake(0.0, 0.0);
gradLayer.endPoint = CGPointMake(1.0, 0.0);//从左到右 按照实际情况自行调整
return gradLayer;
return nil;
}

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