title: Swift: Gradient along a bezier path (using CALayers)
body: <p>I have a relatively straight forward implementation of a progress view set up with CALayer objects. The progress view itself is a subview of UIView. </p>
  
  <p>Here is the code that sets up the progress ring:</p>
  
  <pre><code>        self.progressRingLayer = CAShapeLayer()
  
          let innerRect = CGRectInset(bounds, CGFloat(self.lineWidth) / 2, CGFloat(self.lineWidth) / 2)
          let innerPath = UIBezierPath(ovalInRect: innerRect)
  
          self.progressRingLayer.path = innerPath.CGPath
          self.progressRingLayer.fillColor = UIColor.clearColor().CGColor
          self.progressRingLayer.strokeColor = kProgressColor.CGColor
          self.progressRingLayer.anchorPoint = CGPointMake(0.5, 0.5)
          self.progressRingLayer.transform = CATransform3DRotate(self.progressRingLayer.transform, (CGFloat(M_PI))*1, 0, 0, 1)
          self.progressRingLayer.lineCap = kCALineCapRound
          self.progressRingLayer.lineWidth = CGFloat(self.lineWidth)
  
          self.layer.addSublayer(self.progressRingLayer)
  </code></pre>
  
  <p>What I am trying to do now is add a gradient to the progressRingLayer that follows (or bends with) the path. I have been successful in adding a linear gradient to the fill, but not to just the path.</p>
  
  <p>Here is an example of what effect I want: </p>
  
  <p><img src="https://i.stack.imgur.com/dXyJS.png" alt="enter image description here"></p>
  
  <p>So far everything I have found requires a bunch of additional steps with CoreGraphics and CGContext that don't quite fit with my implementation. Any help would be great, thanks! </p>