MCScratchImageView
A custom ImageView that is used to cover the surface of other view like a scratch card, user can swipe the mulch to see the view below.
Install / Use
/learn @JaylenCoding/MCScratchImageViewREADME
MCScratchImageView

GIF Showcase


Requirments
iOS 8.0+ Xcode 7.2+ Swift 4.0
Installation
CocoaPods
pod "MCScratchImageView"
Manually
Just drag MCScratchImageView.swift to the project tree
Usage
Import
If you use CocoaPods, first import MCScratchImageView
import MCScratchImageView
Define the class variables
var scratchImageView: MCScratchImageView!
Initialize it
// init()
scratchImageView = MCScratchImageView()
// init(frame:)
scratchImageView = MCScratchImageView(frame: yourRect)
Or use StoryBoard.
Set the mask image & radius
// use default touch point radius
scratchImageView.setMaskImage(yourUIImage)
// use custom touch point radius
scratchImageView.setMaskImage(yourUIImage, spotRadius: 100)
Implement the delegate methods:
// set the delegate
scratchImageView.delegate = ***
/* ... */
// implement the MCScratchImageViewDelegate method
extension YourController: MCScratchImageViewDelegate {
func mcScratchImageView(_ mcScratchImageView: MCScratchImageView, didChangeProgress progress: CGFloat) {
print("Progress did changed: " + String(format: "%.2f", progress))
if (progress >= 0.8) {
mcScratchImageView.scratchAll()
}
}
}
API declaration
// current scratched progress
public var progress: CGFloat
// Determin the radius of the touch point
private(set) var spotRadius: CGFloat = 45.0
// set the mask image & radius
public func setMaskImage(_ image: UIImage)
public func setMaskImage(_ image: UIImage, spotRadius: CGFloat)
// scratch all mask fields
public func scratchAll()
Example Project
In "Example" folder.
Tips
- Don't set the scratchImageView.image directlly, you need to use setMaskImage(paras) to set the mask image.
- Don't set the touch point radius (var spotRadius: CGFloat) directlly.
- The contentMode should use default resize mode.
Author
Minecode, minecoder@163.com
License
MCScratchImageView is available under the MIT license. See the LICENSE file for more info.
Related Skills
node-connect
346.8kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
107.6kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
346.8kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
346.8kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
