Giter Club home page Giter Club logo

scratchcardview's Introduction

ScratchCardView

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"

Documentation

Extensive documentation can be found Here.

Special thanks to the Jazzy project for automatic documentation generation.

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.

scratchcardview's People

Contributors

pgorzelany avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

scratchcardview's Issues

Feature Request

If you have time, a few features that would make this even better.

• Ability to get percent value of amount of view thats scratched off.
• A way to clear mask
• Delegate methods for when scratching occurs, when it stops

Thanks

scratchView.clear() Method does not work

After scratchPercent bigger than wanted I call clear method but it behaves like a reload method and makes view unscratched. Do you have any idea about this unexpected behavior

coverView

Hello, how to set the coverView to translucent

Not working using basic sample

`import UIKit
import ScratchCardView

class ViewController: UIViewController {

@IBOutlet weak var scratchCardView: ScratchCardView!


override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.
    
     configureScratchCardView()
    
}


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

}

}

extension ViewController: 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: #imageLiteral(resourceName: "tailor-image"))
    imageView.contentMode = .scaleAspectFill
    return imageView
}

}`

Nothing scratching off.

Adding two images not working

Hi,

I am trying to use 2 images as a cover and container. But the cover and container images show as the same. When scratching nothing is actually seen.

I am using Xcode 9.4.2

scratchPercent attribute of view corrupts

UIView+Extensions.swift class line 47
// The alpha value is the last 8 bits of the data
let alphaValue = imageDataPointer[pixelDataPosition + 3]

Error: Thread 1: EXC_BAD_ACCESS (code=1, address=0x115668003)

Phone: Iphone 11
IOS Version: 13.2

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.