Skip to content

CAPTCHA - Completely Automated Public Turing test to tell Computers and Humans Apart

License

Notifications You must be signed in to change notification settings

William-Weng/WWCaptchaView

Repository files navigation

WWCaptchaView

Swift-5.6 iOS-14.0 Swift Package Manager-SUCCESS LICENSE

Example.gif

dependencies: [
    .package(url: "https://github.com/William-Weng/WWCaptchaView.git", .upToNextMajor(from: "1.1.5"))
]
函式 功能
configure(delegate:stringModel:lineModel:) 設定初始值
generate(captchaString:) 生成驗證碼
函式 功能
captchaView(_:didTouched:) 畫面被點到
captchaView(_:character:at:frame:) 取得各別驗證碼的相關訊息
captchaView(_:string:) 取得驗證碼

Example

import UIKit
import WWCaptchaView

final class ViewController: UIViewController {
    
    @IBOutlet weak var captchaLabel: UILabel!
    @IBOutlet weak var captchaView: WWCaptchaView!
    
    private let stringModel: WWCaptchaView.RandomStringModel = .init(
        digits: "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890甲乙丙丁戊己庚辛壬癸",
        length: 3,
        font: .systemFont(ofSize: 24),
        upperBound: 36,
        textColorType: .random(true)
    )
    
    private let lineModel: WWCaptchaView.RandomLineModel = .init(
        count: 5,
        width: 1.0
    )
    
    override func viewDidLoad() {
        super.viewDidLoad()
        captchaView.configure(delegate: self, stringModel: stringModel, lineModel: lineModel)
        captchaView.generate(captchaString: "8庚M")
    }
}

extension ViewController: WWCaptchaViewDelegate {
    
    func captchaView(_ captchaView: WWCaptchaView, didTouched touchs: Set<UITouch>) {
        captchaView.generate()
    }
        
    func captchaView(_ captchaView: WWCaptchaView, character: String, at index: Int, frame: CGRect) {
        print("[\(index)] \(character) => \(frame)")
    }
    
    func captchaView(_ captchaView: WWCaptchaView, string: String?) {
        captchaLabel.text = string
    }
}

About

CAPTCHA - Completely Automated Public Turing test to tell Computers and Humans Apart

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages