

dependencies: [
.package(url: "https://github.com/William-Weng/WWCaptchaView.git", .upToNextMajor(from: "1.1.5"))
]
| 函式 (Optional, can be removed as it's redundant with the title) |
功能 (Optional, can be removed as it's redundant with the title) |
| configure(delegate:stringModel:lineModel:) |
设置初始值 |
| generate(captchaString:) |
生成验证码 |
| 函式 (Optional, can be removed as it's redundant with the title) |
功能 (Optional, can be removed as it's redundant with the title) |
| 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
}
}