I am creating the circle below using a UIBezierPath. Notice that that there are two different colors on opposite sides of the circle. I would like to round the top and bottom of each little rectangle in the picture.
I want each one of the rectangles' (they are technically dashes) to have a rounded top and bottom. Like this:
Currently I am using this code to make the circle:
let bounds = self.view.bounds
let arcCenter = CGPoint(x: bounds.midX, y: bounds.midY)
let whiteLayer = CAShapeLayer()
let redLayer = CAShapeLayer()
whiteLayer.fillColor = UIColor.clear.cgColor
whiteLayer.strokeColor = UIColor.white.cgColor
var whiteRing = UIBezierPath(arcCenter: arcCenter, radius: CGFloat(125), startAngle: 0, endAngle: CGFloat.pi, clockwise: false)
whiteRing.rotateAroundPoint(angle: CGFloat.pi/2, center: arcCenter)
whiteLayer.lineWidth = 10
whiteLayer.lineDashPattern = [2, 3]
whiteLayer.path = whiteRing.cgPath
redLayer.fillColor = UIColor.clear.cgColor
redLayer.strokeColor = UIColor.red.cgColor
var redRing = UIBezierPath(arcCenter: arcCenter, radius: CGFloat(125), startAngle: 0, endAngle: CGFloat.pi, clockwise: true)
redRing.rotateAroundPoint(angle: CGFloat.pi/2, center: arcCenter)
redLayer.lineWidth = 10
redLayer.lineDashPattern = [2, 3]
redLayer.path = redRing.cgPath
self.view.layer.addSublayer(whiteLayer)
self.view.layer.addSublayer(redLayer)
I honestly don't know if this is possible with a UIBezierPath, I was trying to use something like a CAReplicatorLayer to accomplish this, but I can't seem to figure out how to consistently get the same kind of spacing in between each dash/rectangle and the two separate parts of the circle to avoid overlapping of the white and red parts. Doing this without having to have two different colors would be much easier, but for my use case I must have two different colors. So is there anyway to do this with UIBezierPath, and if not, how would I use CAReplicatorLayer to create the circle in the first picture with each little dash/rectangle having a rounded top and bottom?