How to crop the UIView as semi circle?

Viewed 12715

I want to crop UIView in semi circle shape

like this image

Thanks in advance.

3 Answers

it works in swift 4 and swift 5 for this issue.

let yourView = (is the view you want to crop semi circle from top)

 let circlePath = UIBezierPath(arcCenter: CGPoint(x: yourView.bounds.size.width / 2, y: yourView.bounds.size.height), radius: yourView.bounds.size.height, startAngle: 0.0, endAngle: .pi, clockwise: false)
    let circleShape = CAShapeLayer()
    circleShape.path = circlePath.cgPath
    yourView.layer.mask = circleShape
Related