title: Drawing elements in drawRect on top of a CAShapeLayer
body: <p>I am trying to create a ring that animates a fill of a lighter color around it. I plan to draw the circle in drawRect and animate the fill in a CAShapeLayer and draw a white circle on top. So far my circle looks like this in the simulator:</p>
  
  <p><a href="https://i.stack.imgur.com/tO3jm.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/tO3jm.png" alt="enter image description here"></a></p>
  
  <p>I need the lighter color around the edges only. Is it possible to place the CAShapeLayer between the two circles drawn in drawRect? Code below:</p>
  
  <pre><code>class MyTimer: UIView {
  
      let circleBgColor: UIColor = UIColor(colorLiteralRed: 244.0/255.0, green: 165.0/255.0, blue: 35.0/255.0, alpha: 1)
      let circleFgColor : UIColor = UIColor(colorLiteralRed: 254.0/255.0, green: 198.0/255.0, blue: 106.0/255.0, alpha: 1)
  
      let timeLeftLayer = CAShapeLayer()
  
  
      override init(frame: CGRect) {
          super.init(frame: frame)
          self.config()
      }
  
      //Only called in IB
      required init?(coder aDecoder: NSCoder) {
          super.init(coder: aDecoder)
          self.config()
      }
  
      convenience init() {
          self.init(frame: CGRectZero)
      }
  
      //Common code here
      func config() {
  
          backgroundColor = UIColor.clearColor()
  
          //initially full of time left
          let circlePath = UIBezierPath(arcCenter: CGPoint(x: frame.size.width / 2.0, y: frame.size.height / 2.0), radius: frame.size.width/2, startAngle: 0.0, endAngle: CGFloat(M_PI), clockwise: true)
          timeLeftLayer.path = circlePath.CGPath
          timeLeftLayer.fillColor = circleFgColor.CGColor
          timeLeftLayer.strokeEnd = 1
  
      }
  
  
  
      override func drawRect(rect: CGRect) {
  
          let outterCirclePath = UIBezierPath(ovalInRect: rect)
          circleBgColor.setFill()
          outterCirclePath.fill()
  
  
          layer.addSublayer(timeLeftLayer)
  
  
          let centerCirclePath = UIBezierPath(arcCenter: CGPoint(x: rect.size.width/2, y: rect.size.height/2), radius: rect.size.height*0.4, startAngle: 0, endAngle: CGFloat(M_PI*2), clockwise: true
          )
  
          UIColor.whiteColor().setFill()
          centerCirclePath.fill()
  
  
      }
  
  }
  </code></pre>
  
  <p>any pointers on this would be great. thanks</p>