我实现了CAShapeLayer
画一个圆。这个圆圈有一个笔触,我想包含一个渐变。
如何将您在下面的代码中看到的渐变添加到shapeLayer
:shapeLayer.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)
}