title: How to draw a rounded rectangle with UIBezierPath?
body: <p>I'm trying to mask a view with a rounded rectangle <code>UIBezierPath</code>. I want the mask to look <strong>exactly</strong> the same as if I were just setting <code>layer.cornerRadius</code>:</p>
  
  <pre><code>let frame = CGRect(x: 0, y: 0, width: 80, height: 80)
  let cornerRadius = 30
  </code></pre>
  
  <p><strong>Using <code>cornerRadius</code></strong>:</p>
  
  <pre><code>let view = UIView(frame: frame)
  view.layer.cornerRadius = cornerRadius
  </code></pre>
  
  <p><strong>Using <code>UIBezierPath</code> mask</strong>:</p>
  
  <pre><code>let view = UIView(frame: frame)
  let maskingShape = CAShapeLayer()
  maskingShape.path = UIBezierPath(roundedRect: frame, cornerRadius: cornerRadius).cgPath
  view.layer.mask = maskingShape
  </code></pre>
  
  <p>The resulting rounded rects are completely different. The standard cornerRadius works as expected while the bezier path just snaps to a full circle at a certain radius.</p>
  
  <p><a href="https://i.stack.imgur.com/AbVyw.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/AbVyw.png" alt="enter image description here"></a></p>
  
  <p>Apparently, this is intended behaviour from iOS 7. </p>
  
  <p><strong>How then do I draw a standard rounded rectangle with a bezier path?</strong> </p>
  
  <p>I found <a href="https://www.paintcodeapp.com/news/code-for-ios-7-rounded-rectangles" rel="nofollow noreferrer">this category</a> but this has to be a joke right? Is there no simpler way? :(</p>
  
  <p><strong><a href="https://stackoverflow.com/questions/24936003/crazy-rounded-rect-uibezierpath-behavior-on-ios-7-what-is-the-deal">Related question</a></strong>.</p>