/CodeTextField

验证码文本框、密码框、等

Primary LanguageSwiftMIT LicenseMIT

CodeTextField

Lint Version License Platform

Requirements:

  • iOS 9.0+
  • Xcode 10.1+
  • Swift 5.0

Installation Cocoapods

pod 'CodeTextField', '~> 0.4.0'

Demo Figure

Usage

1. 样式1

    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.样式2

    /// 样式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
    }()

Reference

License

CodeTextField is released under an MIT license. See LICENSE for more information.