-1

Currently i am adding the changes as subview to the original image. I want to add an eraser tool so that when the user draws on the screen, the subviews will be cleared and the underlined image will be seen . Same as an eraser tool in "Paint".Below is the code used for drawing a rectangle.How can i add an eraser tool using the same method. Thank you

case 2:
            let path = UIBezierPath()
            let sh = CAShapeLayer()
            sh.strokeColor = selectedcolor.cgColor
            sh.lineWidth = 3
            sh.fillColor = UIColor.clear.cgColor
            tempImage.layer.sublayers?.removeAll()
            sh.fillColor = UIColor.clear.cgColor
            path.move(to: startPoint)
            sh.path = UIBezierPath(rect: rect).cgPath
            tempImage.layer.addSublayer(sh)
            if usermoving == 0
            {
                sh.setValue(tag, forKey: "tag")
                mainImage.layer.addSublayer(sh)  
             }
            break
Faheem Rahman
  • 343
  • 2
  • 10

1 Answers1

0

Its Objective C Code

If you are using an image as background then you can set the same image as brush pattern to draw the bezierpath it will virtually give you the eraser effect.

Swift:-

UIColor(patternImage: UIImage(named: "background.png"))

user1376400
  • 614
  • 1
  • 4
  • 8