- CAPTCHA - Completely Automated Public Turing test to tell Computers and Humans Apart
- 全自動區分電腦和人類的圖靈測試(英語:Completely Automated Public Turing test to tell Computers and Humans Apart,簡稱CAPTCHA),又稱驗證碼
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:) | 取得驗證碼 |
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
}
}