为CAShapeLayer的笔触添加渐变

时间:2019-05-11 23:48:54

标签: ios swift

我实现了CAShapeLayer画一个圆。这个圆圈有一个笔触,我想包含一个渐变。

如何将您在下面的代码中看到的渐变添加到shapeLayershapeLayer.strokeColor = ...的笔划中。

代码:

func displayCircle() {
        let color = UIColor(red: 11/255, green: 95/255, blue: 244/255, alpha: 1)
        let sndColor = UIColor(red: 106/255, green: 178/255, blue: 255/255, alpha: 1)

        gl = CAGradientLayer()
        gl.colors = [color.cgColor, sndColor.cgColor]
        gl.locations = [0.0, 1.0]

        let trackLayer = CAShapeLayer()
        let center = CGPoint(x: circleView.frame.size.width/2, y: circleView.frame.size.height / 1.3)
        let circularPath = UIBezierPath(arcCenter: center, radius: 120, startAngle: CGFloat.pi, endAngle: 2 * CGFloat.pi, clockwise: true)

        ...

        shapeLayer.path = circularPath.cgPath
        shapeLayer.strokeColor = ???
        shapeLayer.lineWidth = 15
        shapeLayer.fillColor = UIColor.clear.cgColor
        shapeLayer.strokeEnd = 0

        ...
        circleView.layer.addSublayer(shapeLayer)
    }

0 个答案:

没有答案