HomeiOS DevelopmentRounded nook of a cut-out arc utilizing UIBezierPath

Rounded nook of a cut-out arc utilizing UIBezierPath


I am drawing a cut-out gap in CAShapeLayer utilizing UIBezierPath, that is the code I’ve to date:

let view = UIView(
  body: CGRect(origin: .zero, measurement: CGSize(width: 500.0, peak: 500.0))
)
view.backgroundColor = .clear

let shapeLayer = CAShapeLayer()
shapeLayer.body = view.bounds
shapeLayer.fillColor = UIColor.systemMint.cgColor

let mainPath = UIBezierPath(
  roundedRect: CGRect(
    origin: CGPoint(x: 50.0, y: 50.0), measurement: CGSize(width: 400.0, peak: 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.shut()

mainPath.append(cutOutArc)

shapeLayer.fillRule = .evenOdd
shapeLayer.path = mainPath.cgPath

view.layer.insertSublayer(shapeLayer, at: 0)

(The code is simplified and tailored to make use of in Playground.)

The code outcomes on this form (seems to be precisely as I would like):

Rounded nook of a cut-out arc utilizing UIBezierPath

What I cannot determine easy methods to do is including a nook radius to the cut-out arc (the place the purple arrows within the picture beneath level), say, of 4.0 factors. I’ve performed with fairly random choices for a pair days now with no significant consequence. I attempted to ask AI, and it could not determine it both (it simply saved on producing damaged code actually).

A square shape with a half-arc cut-out hole in the centre of the left edge, and red arrows pointing to the place, where I need to add corner radius

Does anybody know easy methods to do it? Any steering is way appreciated!

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments