Setting rounded corners via CAShapeLayer.path looks problematic

class ViewController: UIViewController {
  override func viewDidLoad() {
    super.viewDidLoad()

    view.backgroundColor = .white
    
    do {
      let shapeLayer = CAShapeLayer()
      shapeLayer.frame = CGRect(x: 50, y: 100, width: 200, height: 108)
      let path = UIBezierPath(roundedRect: shapeLayer.bounds, cornerRadius: 36)
      shapeLayer.path = path.cgPath
      shapeLayer.fillColor = UIColor.orange.cgColor
      view.layer.addSublayer(shapeLayer)
    }
    do {
      let layer = CALayer()
      layer.backgroundColor = UIColor.blue.cgColor
      layer.cornerRadius = 36
      layer.frame = CGRect(x: 50, y: 300, width: 200, height: 108)
      view.layer.addSublayer(layer)
    }

  }
}

The corner radius is set to 36 through CAShapeLayer, but the actual effect is larger than 36, close to half of the height. Setting it through CALayer is fine Can anyone explain it to me? Thank you

This is a long-standing bug.

When the cornerRadius is greater than ~65.5% of min(height, width) it seems to be drawn as half of height or width.

You can write your own function to create a path with rounded corners using addArc for circular or addQuadCurve for continuous rounding.

Setting rounded corners via CAShapeLayer.path looks problematic
 
 
Q