Skip to content

GuibinLu/ScratchCardView

 
 

Repository files navigation

ScratchCardView

CI Status Version License Platform

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Installation

ScratchCardView is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "ScratchCardView"

Usage

See the example project for usage.

You can setup custom views for both the scratch card cover and the cratch card content. The setup is done through a delegate.

class YourViewController: UIViewController {
    ...
    override func viewDidLoad() {
        super.viewDidLoad()

        configureScratchCardView()
    }

    private func configureScratchCardView() {
        scratchCardView.delegate = self
        scratchCardView.scratchWidth = 150
    }
}

extension YourViewController: ScratchCardViewDelegate {

    func coverView(for scratchCardView: ScratchCardView) -> UIView {
        let coverView = UIView()
        coverView.backgroundColor = UIColor.gray
        return coverView
    }

    func contentView(for scratchCardView: ScratchCardView) -> UIView {
        let imageView = UIImageView(image: yourCustomImage)
        imageView.contentMode = .scaleAspectFill
        return imageView
    }
}

That is all you need to know, its that simple :)

If you want to reload the ScratchCardView call:

scratchCardView.reloadView()

This will trigger a call to your delegate for a new cover and content view.

Author

pgorzelany, [email protected]

License

ScratchCardView is available under the MIT license. See the LICENSE file for more info.

About

A scratch card view for iOS

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Swift 82.1%
  • Ruby 17.9%