3

I want to draw 3/4 of a circle with a gradient border, like this:

enter image description here

I can draw this circle with this code:

func createProgressLayer() {
     let startAngle = CGFloat(M_PI_2)
     let endAngle = CGFloat(M_PI * 2 )
     let centerPoint = CGPointMake(CGRectGetWidth(frame)/2 , CGRectGetHeight(frame)/2)

     let gradientMaskLayer = gradientMask()
     progressLayer.path = UIBezierPath(arcCenter:centerPoint, radius: CGRectGetWidth(frame)/2 - 30.0, startAngle:startAngle, endAngle:endAngle, clockwise: true).CGPath
     progressLayer.backgroundColor = UIColor.clearColor().CGColor
     progressLayer.fillColor = nil
     progressLayer.strokeColor = UIColor.blackColor().CGColor
     progressLayer.lineWidth = 4.0
     progressLayer.strokeStart = 0.0
     progressLayer.strokeEnd = 0.0    
}

But I want to add a Gradient effect, Please help. Thanks.

mugx
  • 9,869
  • 3
  • 43
  • 55
Tejas Ardeshna
  • 4,343
  • 2
  • 20
  • 39
  • 1
    There's no built-in way to draw an angle gradient, only linear or radial (concentric). Check this question: http://stackoverflow.com/questions/5379234/how-to-make-a-conical-gradient-in-ios-using-core-graphics-quartz-2d – Cyrille Jul 08 '16 at 08:57
  • The easiest way would be adding a gradient view on top of the circle view and position the gradient view as per your requirements. – Teja Nandamuri Jul 08 '16 at 15:31
  • @TejaNandamuri Can you please show code? – Tejas Ardeshna Jul 11 '16 at 05:50

0 Answers0