title: How to apply corner radius to specific corners for a CAShapeLayer, not UIView
body: <p>I am drawing a bar chart and I want each bar to have a corner radius just on top.</p>
  
  <p>Here is my code to draw a bar:</p>
  
  <pre><code>let barLayer = CAShapeLayer()
  barLayer.frame = CGRect(x: xPos, y: yPos, width: barWidth, height: mainLayer.frame.height - bottomSpace - yPos)
  
  let path =  UIBezierPath(roundedRect: barLayer.frame, byRoundingCorners: [.topLeft, .topRight], cornerRadii: CGSize(width: 5.0, height: 5.0))
  barLayer.path = path.cgPath
  barLayer.backgroundColor = color.cgColor
  mainLayer.addSublayer(barLayer)
  </code></pre>
  
  <p>When applying this to an <code>UIView</code> I would just add another line:</p>
  
  <pre><code>myView.layer.mask = barLayer 
  </code></pre>
  
  <p>But working with <code>CAShapeLayer</code> got me a little confused. How can I add the corner radius to it ?</p>
  
  <p>This is what I want to achieve:</p>
  
  <p><a href="https://i.stack.imgur.com/lA6bg.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/lA6bg.png" alt="enter image description here"></a></p>
  
  <p>edit2: trying to use two layers:</p>
  
  <pre><code>let cornerRadiusLayer = CAShapeLayer()
  cornerRadiusLayer.frame = CGRect(x: xPos, y: yPos, width: barWidth, height: mainLayer.frame.height - bottomSpace - yPos)
  let path =  UIBezierPath(roundedRect: cornerRadiusLayer.frame, byRoundingCorners: [.topLeft, .topRight], cornerRadii: CGSize(width: 5.0, height: 5.0))
  cornerRadiusLayer.path = path.cgPath
  
  let barLayer = CALayer()
  barLayer.frame = CGRect(x: xPos, y: yPos, width: barWidth, height: mainLayer.frame.height - bottomSpace - yPos)
  barLayer.backgroundColor = color.cgColor
  barLayer.mask = cornerRadiusLayer
  mainLayer.addSublayer(barLayer)
  </code></pre>