ios 渐变色

colors 渐变的颜色
locations 颜色变化位置的取值范围
startPoint 颜色渐变的起始位置:取值范围在(0,0)~(1,1)之间
endPoint 颜色渐变的终点位置,取值范围也是在(0,0)~(1,1)之间
补充下:startPoint & endPoint设置为(0,0)(1.0,0)代表水平方向渐变,(0,0)(0,1.0)代表竖直方向渐变

  CAGradientLayer * gradientLayer = [CAGradientLayer layer];
    gradientLayer.frame = self.button1.bounds;
    gradientLayer.colors = @[(__bridge id)[UIColor redColor].CGColor,(__bridge id)[UIColor yellowColor].CGColor];
    gradientLayer.startPoint = CGPointMake(0, 0);
    gradientLayer.endPoint = CGPointMake(0, 1);
    gradientLayer.locations = @[@0,@1];
    [self.button1.layer addSublayer:gradientLayer];

你可能感兴趣的:(ios 渐变色)