- 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.0.2"))
]
函式 | 功能 |
---|---|
configure(delegate:stringModel:lineModel) | 設定初始值 |
redrawCaptcha() | 重新繪製驗證碼 |
redrawCaptchaString(_:) | 重新繪製自訂驗證碼 |
import UIKit
import WWPrint
import WWCaptchaView
// MARK: - ViewController
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: 56),
upperBound: 10,
color: .black
)
private let lineModel: WWCaptchaView.RandomLineModel = .init(
count: 5,
width: 1.0
)
override func viewDidLoad() {
super.viewDidLoad()
captchaView.configure(delegate: self, stringModel: stringModel, lineModel: lineModel)
}
}
// MARK: - WWCaptchaViewDelegate
extension ViewController: WWCaptchaViewDelegate {
func captcha(view: WWCaptchaView, string: String?) { captchaLabel.text = string }
}