I’m drawing a cut-out hole in CAShapeLayer using UIBezierPath, this is the code I have so far:
let view = UIView(
frame: CGRect(origin: .zero, size: CGSize(width: 500.0, height: 500.0))
)
view.backgroundColor = .clear
let shapeLayer = CAShapeLayer()
shapeLayer.frame = view.bounds
shapeLayer.fillColor = UIColor.systemMint.cgColor
let mainPath = UIBezierPath(
roundedRect: CGRect(
origin: CGPoint(x: 50.0, y: 50.0), size: CGSize(width: 400.0, height: 400.0)
),
cornerRadius: 10.0
)
let cutOutArc = UIBezierPath()
cutOutArc.addArc(
withCenter: CGPoint(x: 50.0, y: 250.0),
radius: 50.0,
startAngle: .pi / 2.0,
endAngle: .pi + .pi / 2.0,
clockwise: false
)
cutOutArc.addLine(to: CGPoint(x: 50.0, y: 200.0))
cutOutArc.close()
mainPath.append(cutOutArc)
shapeLayer.fillRule = .evenOdd
shapeLayer.path = mainPath.cgPath
view.layer.insertSublayer(shapeLayer, at: 0)
(The code is simplified and adapted to use in Playground.)
The code results in this shape (looks exactly as I need):

What I can’t figure out how to do is adding a corner radius to the cut-out arc (where the red arrows in the image below point), say, of 4.0 points. I’ve played with pretty random options for a couple days now with no meaningful result. I tried to ask AI, and it couldn’t figure out it either (it just kept on producing broken code really).

Does anyone know how to do it? Any guidance is much appreciated!
