You can draw a circle in the draw(_ rect: CGRect) method with using a bezier path like below.
import UIKit
import CoreGraphics
class CircleView: UIView {
var radius: Double = 200.0
var lineWidth: CGFloat = 5.0
var centre = CGPoint.zero
override func draw(_ rect: CGRect) {
var arrRadians = [Double]()
let pieVal = Double.pi * 2.0
let incrVal = pieVal / 100
arrRadians = stride(from: 0, to: 100, by: incrVal).map{$0}
for rad in arrRadians {
let sinRad = (sin(rad) * radius) + Double((rect.size.width / 2))
let cosRad = (cos(rad) * radius) + Double((rect.size.height / 2))
let point = CGPoint(x: sinRad, y: cosRad)
let path = UIBezierPath()
path.move(to: centre == CGPoint.zero ? point : centre)
path.addLine(to: point)
centre = point
let shapeLayer = CAShapeLayer()
shapeLayer.path = path.cgPath
shapeLayer.strokeColor = UIColor.red.cgColor
shapeLayer.lineWidth = lineWidth
self.layer.addSublayer(shapeLayer)
}
}
}
Then use setNeedsDisplay() method in for changing the radius of the circle.
viewCircle.radius = 100
viewCircle.setNeedsDisplay()
Result:
![enter image description here](https://i.stack.imgur.com/ZOOS8.png)