What I would do is draw a gradient layer and then draw on top of that layer, which is black with the arc removed.
Here is my attempt at an approximate image that you provided (I omitted the white mark in the center, but this is trivial):

And here is the code that generated it:
let r = CGRectMake(100,100,130,100) let g = CAGradientLayer() g.frame = r let c1 = UIColor( red: 151.0/255.0, green: 81.0/255.0, blue: 227.0/255.0, alpha: 1) let c2 = UIColor( red: 36.0/255.0, green: 176.0/255.0, blue: 233.0/255.0, alpha: 1) g.colors = [c1.CGColor as AnyObject, c2.CGColor as AnyObject]; self.view.layer.addSublayer(g) let percent = CGFloat(0.64) // percentage of circle UIGraphicsBeginImageContextWithOptions(r.size, false, 0) let con = UIGraphicsGetCurrentContext() CGContextFillRect(con, CGRect(origin: CGPoint(), size: r.size)) CGContextSetLineWidth(con, 5) CGContextSetLineCap(con, kCGLineCapRound) CGContextSetBlendMode(con, kCGBlendModeClear) let pi = CGFloat(M_PI) CGContextAddArc(con, r.size.width/2.0, r.size.height/2.0, 30, -pi/2.0, -pi/2.0 + percent*pi*2.0, 0) CGContextStrokePath(con) let im = UIGraphicsGetImageFromCurrentImageContext() UIGraphicsEndImageContext() let b = CALayer() b.frame = r b.contents = im.CGImage self.view.layer.addSublayer(b)
The gradient level (the first part of the code) is just a service offer. If this is not the gradient you want, you can create your own. You can draw it in Photoshop and use the image as the content of the gradient layer. Or you can make the layer “angular” in your code using third-party code, for example https://github.com/paiv/AngleGradientLayer . The purpose of the example is simply to show how you can “erase” an arc in a black layer to reveal the gradient hidden behind it and, thus, draw a gradient.
source share