1

i am trying to draw text in center of white circle and the text color should be transparent so it represent color of background view. hence as the color of background view(i.e gradient color) changes the color of text also changes.

Below is code that is used to draw white circle

        let circleLayer = CAShapeLayer();
        circleLayer.path = UIBezierPath(ovalIn: CGRect(x: self.view.frame.width/2 - 87, y: self.view.frame.height/2 - 87, width: 174, height: 174)).cgPath;
        circleLayer.strokeColor = UIColor.clear.cgColor;
        circleLayer.fillColor = UIColor.white.cgColor;
        self.view.layer.addSublayer(circleLayer)

Now i need to add text to this white circle which is transparent, as in which represent the color of background view

OR overall simply we can say that, i need to cut out the white circle in form of text so the background view color can be seen from that cutted part

Any help would be great..!

Thank You.

Zღk
  • 854
  • 7
  • 25

1 Answers1

0

Create a UILabel and add it as a subview to CALayer

let label = UILabel()
label.frame = CGRect(x: circleLayer.frame.origin.x + (circleWidth/2), y: circleLayer.frame.origin.y, width: circleLayer.bounds.width, height: circleLayer.bounds.height)
label.text = "Hello"
label.textColor = *Your background color*
label.isHidden = false

circleLayer.addSublayer(label.layer)
abh
  • 1,189
  • 2
  • 14
  • 30
  • text should be tranparent or somthing like that so it directly shows color of background view @Babar – Zღk Feb 08 '21 at 06:02