make a rounded circle in swift with diameter of 80 in swift

You can make a rounded circle in Swift using CAShapeLayer. Here's an example:

main.swift
let circleLayer = CAShapeLayer()
circleLayer.path = UIBezierPath(ovalIn: CGRect(x: 0, y: 0, width: 80, height: 80)).cgPath
circleLayer.fillColor = UIColor.clear.cgColor
circleLayer.strokeColor = UIColor.black.cgColor
circleLayer.lineWidth = 1.0
circleLayer.lineCap = CAShapeLayerLineCap.round

yourView.layer.addSublayer(circleLayer)
334 chars
9 lines

In the code above, we create an instance of CAShapeLayer and set its path property to a UIBezierPath representing an oval with a width and height of 80. We also set the fillColor to clear so the circle will be transparent inside, and set the strokeColor to black with a lineWidth of 1.0, which gives us the rounded circle shape. Lastly, we set the lineCap to round to ensure the ends of the stroke are rounded, and add the layer to our yourView. This will create a rounded circle in yourView with a diameter of 80.

gistlibby LogSnag