Scratch Card effect in Swift 3

前端 未结 3 811
心在旅途
心在旅途 2021-01-17 05:22

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

相关标签:
3条回答
  • 2021-01-17 05:39

    Check this Swift 3 example of ScratchCardImageView

    A simple UIImageView subclass that allows your UIImageView become a scratch card.

    0 讨论(0)
  • 2021-01-17 05:44

    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()
        }
    
    0 讨论(0)
  • 2021-01-17 05:55

    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.

    0 讨论(0)
提交回复
热议问题