刮刮卡 1.1.3

刮刮卡 1.1.3

测试已测试
语言语言 SwiftSwift
许可 MIT
发布上次发布2017年12月
SwiftSwift版本3.0
SPM支持SPM

joehour维护。



刮刮卡 1.1.3

  • joe

刮刮卡

需求

  • iOS 8.0+
  • Xcode 8.0+ Swift 3

安装

CocoaPods

请查看cocoapods.org上的开始选项卡。

要在项目中使用ScratchCard,请将以下'Podfile'添加到您的项目中

pod 'ScratchCard', '~> 1.1.3'

然后运行

pod install

源代码

将ScratchView.swift和ScratchUIView.swift复制到您的项目。

然后导入选定的ScratchCard到您的文件。

示例

请查看包含的示例项目。

用法

  • 样本
    import ScratchCard
    
    class ViewController: UIViewController {

    var scratchCard: ScratchUIView!
    override func viewDidLoad() {
        super.viewDidLoad()
        
        scratchCard  = ScratchUIView(frame: CGRect(x:50, y:80, width:320, height:480),Coupon: "image.jpg", MaskImage: "mask.png", ScratchWidth: CGFloat(40))
        
        self.view.addSubview(scratchCard)
        }
    }

刮擦百分比

获取刮擦百分比非常容易。

  • 样本
   let scratchPercent: Double = scratchCard.getScratchPercent()

处理刮擦事件

处理刮擦事件(ScratchBegan、ScratchMoved和ScratchEnded)非常容易。

您可以在刮刮卡中获取刮擦位置。

请在您的代码中设置ScratchUIViewDelegate。

  • 样本
class ViewController: UIViewController, ScratchUIViewDelegate {
    
    var scratchCard: ScratchUIView!
    override func viewDidLoad() {
        super.viewDidLoad()

        scratchCard = ScratchUIView(frame: CGRect(x:50, y:80, width:320, height:480), Coupon: "image", MaskImage: "mask", ScratchWidth: CGFloat(40))
        scratchCard.delegate = self
        
        self.view.addSubview(scratchCard)
    }
    
    //Scratch Began Event(optional)
    func scratchBegan(_ view: ScratchUIView) {
        print("scratchBegan")
        
        ////Get the Scratch Position in ScratchCard(coordinate origin is at the lower left corner)
        let position = Int(view.scratchPosition.x).description + "," + Int(view.scratchPosition.y).description
        print(position)

    }
    
    //Scratch Moved Event(optional)
    func scratchMoved(_ view: ScratchUIView) {
        let scratchPercent: Double = scratchCard.getScratchPercent()
        textField.text = String(format: "%.2f", scratchPercent * 100) + "%"
        print("scratchMoved")
        
        ////Get the Scratch Position in ScratchCard(coordinate origin is at the lower left corner)
        let position = Int(view.scratchPosition.x).description + "," + Int(view.scratchPosition.y).description
        print(position)
    }
    
    //Scratch Ended Event(optional)
    func scratchEnded(_ view: ScratchUIView) {
        print("scratchEnded")
        
        ////Get the Scratch Position in ScratchCard(coordinate origin is at the lower left corner)
        let position = Int(view.scratchPosition.x).description + "," + Int(view.scratchPosition.y).description
        print(position)

    }
}

许可

ScratchCard采用MIT许可。

版权所有 © 2016 Joe。