I am trying to implement a Scratch Card effect in Swift 3 for my app, I found some examples but they\'re on Objective C (show scratch-card effect with the help of using scra
Check this Swift 3 example of ScratchCardImageView
A simple UIImageView
subclass that allows your UIImageView
become a scratch card.
I found a library that suits your requirement. It is Swift 3 compatible. Try this SRScratchView
ScreenShot
var lineType: CGLineCap = .round
var lineWidth: CGFloat = 30.0
func scrachBetween(fromPoint: CGPoint, currentPoint: CGPoint) {
UIGraphicsBeginImageContext(self.frame.size)
image?.draw(in: self.bounds)
let path = CGMutablePath()
path.move(to: fromPoint)
path.addLine(to: currentPoint)
let context = UIGraphicsGetCurrentContext()!
context.setShouldAntialias(true)
context.setLineCap(lineType)
context.setLineWidth(lineWidth)
context.setBlendMode(.clear)
context.addPath(path)
context.strokePath()
image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
}
You can use ScratchCard library. It has simple API, but I don't know is it Swift 3 compatible. Anyway, you can rewrite it or check its implementation.