/MHVerifyCodeView

A verification code UI library. 一个简单的验证码UI第三方库。

Primary LanguageSwiftMIT LicenseMIT

MHVerifyCodeView

CI Status Version License Platform

Example

VerifyCodeView

Sample

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        loadViews(in: view)
    }
    
    // MARK: View
    
    private func loadViews(in box: UIView) {
        box.backgroundColor = .lightGray
        
        box.addSubview(mhField)
        [mhField].forEach({
            $0.translatesAutoresizingMaskIntoConstraints = false
        })
        NSLayoutConstraint.activate([
            mhField.centerYAnchor.constraint(equalTo: box.centerYAnchor, constant: 0.0),
            
            mhField.leftAnchor.constraint(equalTo: box.leftAnchor, constant: 0.0),
            mhField.rightAnchor.constraint(equalTo: box.rightAnchor, constant: 0.0),
            // Static constraint needed.
            mhField.heightAnchor.constraint(equalToConstant: 64.0),
        ])
    }
    
    private func shouldSendCode(_ code: String) {
        let message = "shouldSendCode, code=\(code)"
        print("MOON__Log" + message)
        let alert = UIAlertController(title: "Hint", message: message, preferredStyle: .alert)
        alert.addAction(UIAlertAction(title: "ok", style: .default))
        present(alert, animated: true)
    }
    
    private lazy var mhField: MHVerifyCodeView = {
        let field = MHVerifyCodeView { [weak self] code in
            self?.shouldSendCode(code)
        }
        return field
    }()
}

Author

feaskters

Contributor

darkThanBlack

Update

2024/03/29. Completely refactored by darkThanBlack.

2020/04/30. Created by feaskters.

License

MHVerifyCodeView is available under the MIT license. See the LICENSE file for more info.