Contents

william-weng/wwcaptchaview

- [CAPTCHA - Completely Automated Public Turing test to tell Computers and Humans Apart](https://zh.wikipedia.org/zh-tw/验证码)

[Introduction - 簡介](https://swiftpackageindex.com/William-Weng)

[Example.gif]

Installation with Swift Package Manager

dependencies: [
    .package(url: "https://github.com/William-Weng/WWCaptchaView.git", .upToNextMajor(from: "1.1.5"))
]

Function - 可用函式

|函式|功能| |-|-| |configure(delegate:stringModel:lineModel:)|設定初始值| |generate(captchaString:)|生成驗證碼|

WWCaptchaViewDelegate

|函式|功能| |-|-| |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
    }
}

Package Metadata

Repository: william-weng/wwcaptchaview

Default branch: main

README: README.md