- iOS 9.0+
- Xcode 10.1+
- Swift 5.0
pod 'CodeTextField', '~> 0.4.0'
private lazy var style1: CodeTextField = {
let temTextField = CodeTextField(codeLength: 4,
characterSpacing: 10,
validCharacterSet: CharacterSet(charactersIn: "0123456789"),
characterLabelGenerator: { (_) -> LableRenderable in
return StyleLabel(size: CGSize(width: 50, height: 50))
})
temTextField.keyboardType = .numberPad
return temTextField
}()
/// 样式2
private lazy var style4: CodeTextField = {
let temTextField = CodeTextField(codeLength: 6,
characterSpacing: 10,
validCharacterSet: CharacterSet(charactersIn: "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"),
characterLabelGenerator: { (idx) -> LableRenderable in
switch idx {
case 0:
return StyleLabel(size: CGSize(width: 50, height: 50))
case 1:
let label = StyleLabel(size: CGSize(width: 50, height: 50))
label.style = Style.border(nomal: UIColor.gray, selected: UIColor.blue)
return label
case 2:
return StyleLabel(size: CGSize(width: 50, height: 50))
case 3:
let label = StyleLabel(size: CGSize(width: 50, height: 50))
label.style = Style.border(nomal: UIColor.gray, selected: UIColor.orange)
return label
case 4:
return StyleLabel(size: CGSize(width: 50, height: 50))
default:
let label = StyleLabel(size: CGSize(width: 50, height: 50))
label.style = Style.border(nomal: UIColor.gray, selected: UIColor.purple)
return label
}
})
temTextField.keyboardType = .asciiCapable
temTextField.autocorrectionType = .no
temTextField.valueChanged = { result in
debugPrint(result)
}
return temTextField
}()
CodeTextField is released under an MIT license. See LICENSE for more information.