iOS 渐变色绘制

1、layer 层绘制

//渐变色 设置
        CAGradientLayer *colorLayer = [CAGradientLayer layer];
        colorLayer.frame = self.bounds;
        colorLayer.colors = @[
                              (__bridge id)[UIColor colorWithHexString:model.color1].CGColor,
                              (__bridge id)[UIColor colorWithHexString:model.color2].CGColor
                              ];
        colorLayer.startPoint = CGPointMake(0, 0);
        colorLayer.endPoint   = CGPointMake(0, 1);
        colorLayer.locations = @[@(0), @(1.0f)];
        [self.contentLayer addSublayer:colorLayer];
        colorLayer.mask = layer;

2、贝塞尔绘制曲线

UIBezierPath *path = [UIBezierPath bezierPath];
        [path addArcWithCenter:self.chartOrigin radius:redius-k_Reduce*i startAngle:lastBegin  endAngle:lastBegin + cuttentpace clockwise:YES];
        layer.path = path.CGPath;

        layer.lineWidth = _ringWidth-k_Reduce*i*2.0;
        [self.contentLayer addSublayer:layer];

3、

你可能感兴趣的:(iOS 渐变色绘制)