0

Click here to see image.

I want to crop out the Red triangle part from the CAshapelayer.

This is the code i used for drawing it:

Radial Gradient background in Swift and my code is:

let bgLayer = RadialGradientLayer(center: speed_dial_center_point, radius: speed_dial_size.width/2, colors: [UIColor.clear.cgColor,UIColor(red: 211/255, green: 211/255, blue: 211/255, alpha: 0.5).cgColor],speed_scale_margin: speed_scale_margin)//CALayer()
            bgLayer.frame = CGRect(origin: rect.origin, size: speed_dial_size)
            bgLayer.contentsScale = self.layer.contentsScale
            bgLayer.setNeedsDisplay()
            backgondArc_Layer.addSublayer(bgLayer)
            self.layer.insertSublayer(backgondArc_Layer, below: speed_dial_layer)
Krunal
  • 77,632
  • 48
  • 245
  • 261

1 Answers1

1

So add a mask layer to your gradient layer that masks out the part you want to remove.

Duncan C
  • 128,072
  • 22
  • 173
  • 272
  • I have given stroke color to clear color that's why it was not masking. cropArea.strokeColor = UIColor.black.cgColor Now after changing it to black, it works. – Bhavesh patel Nov 14 '17 at 13:41
  • 2
    Drawing with clear color does nothing. It's like painting with no paint on your brush. – Duncan C Nov 14 '17 at 18:52