- Imitation Scratch Card function.
- 仿刮刮樂功能。
dependencies: [
.package(url: "https://github.com/William-Weng/WWScratchCard.git", .upToNextMajor(from: "1.0.0"))
]
函式 | 功能 |
---|---|
setting(delegate:couponImage:maskImage:scratchType:contentMode:) | 設定圖片相關設定 |
restart(couponImage:maskImage:contentMode:) | 重新開始 (0%) |
finish() | 全部完成 (100%) |
函式 | 功能 |
---|---|
scratchBegan(point:) | 開始刮 |
scratchMoved(progress:) | 正在刮 |
scratchEnded(point:) | 停止刮 |
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 %"
}
}
}