Here's n quick implementation of a HalfCircleView
using CAShapeLayer and UIBezierPath:
class HalfCircleView: UIView {
override init(frame: CGRect) {
super.init(frame: frame)
setupHalfCircle()
}
required init?(coder: NSCoder) {
super.init(coder: coder)
setupHalfCircle()
}
private func setupHalfCircle() {
let shapeLayer = CAShapeLayer()
let path = UIBezierPath()
path.move(to: CGPoint(x: 0, y: bounds.maxY))
path.addArc(withCenter: CGPoint(x: bounds.midX, y: bounds.maxY),
radius: bounds.width / 2,
startAngle: CGFloat.pi,
endAngle: 0,
clockwise: true)
shapeLayer.path = path.cgPath
shapeLayer.fillColor = UIColor.blue.cgColor
layer.addSublayer(shapeLayer)
}
override func layoutSubviews() {
super.layoutSubviews()
setupHalfCircle()
}
}