WWScratchCard

main

Imitation Scratch Card function.
William-Weng/WWScratchCard

WWScratchCard

Swift-5.6 iOS-14.0 TAG Swift Package Manager-SUCCESS LICENSE

  • Imitation Scratch Card function.
  • 仿刮刮樂功能。

WWScratchCard

dependencies: [
    .package(url: "https://github.com/William-Weng/WWScratchCard.git", .upToNextMajor(from: "1.0.0"))
]

Function - 可用函式

函式 功能
setting(delegate:couponImage:maskImage:scratchType:contentMode:) 設定圖片相關設定
restart(couponImage:maskImage:contentMode:) 重新開始 (0%)
finish() 全部完成 (100%)

WWScratchCardDelegate

函式 功能
scratchBegan(point:) 開始刮
scratchMoved(progress:) 正在刮
scratchEnded(point:) 停止刮

Example

import UIKit
import WWScratchCard

final class ViewController: UIViewController {

    @IBOutlet weak var label: UILabel!
    @IBOutlet weak var scratchCard: WWScratchCardView!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        test()
    }
}

// MARK: - WWScratchCardDelegate
extension ViewController: WWScratchCardDelegate {
    
    func scratchBegan(point: CGPoint) {}
    
    func scratchMoved(progress: Float) {
        let percent = String(format: "%.1f", progress * 100)
        label.text = "\(percent)%"
    }
    
    func scratchEnded(point: CGPoint) {}
}

// MARK: - 小工具
private extension ViewController {
    
    func test() {
        
        guard let couponImage = UIImage(named: "Desktop.png"),
              let maskImage = UIImage(named: "Gray.png")
        else {
            return
        }
        
        scratchCard.setting(delegate: self, couponImage: couponImage, maskImage: maskImage, contentMode: .scaleToFill)
        
        DispatchQueue.main.asyncAfter(deadline: .now() + 5) {
            self.scratchCard.restart(couponImage: couponImage, maskImage: maskImage, contentMode: .scaleToFill)
            self.label.text = "0.0 %"
        }
    }
}

Description

  • Swift Tools 5.6.0
View More Packages from this Author

Dependencies

  • None
Last updated: Fri Oct 18 2024 18:19:55 GMT-0900 (Hawaii-Aleutian Daylight Time)