MKOtpView
示例
要运行示例项目,请克隆仓库,然后首先从 Example 目录运行 pod install
要求
iOS 8.0 或更高版本。
安装
MKOtpView 通过 CocoaPods 提供。要安装它,只需将以下行添加到 Podfile
pod 'MKOtpView'
实现步骤
- 通过传递框架创建 MKOtpView 对象
var otpView:MKOtpView!
otpView = MKOtpView(frame: CGRect(x: 10, y: 100, width: 350, height: 50))
- 现在您可以设置以下不同属性
otpView = MKOtpView(frame: CGRect(x: 10, y: 100, width: 350, height: 50))
otpView.setVerticalPedding(pedding: 5)
otpView.setHorizontalPedding(pedding: 5)
otpView.setNumberOfDigits(numberOfDigits: 6)
otpView.setBorderWidth(borderWidth: 2.0)
otpView.setBorderColor(borderColor: UIColor.green)
otpView.setCornerRadius(radius: 2)
otpView.setInputBackgroundColor(inputBackgroundColor: UIColor.white)
otpView.backgroundColor = UIColor.lightGray
otpView.enableSecureEntries()
self.view.addSubview(otpView)
- 设置闭包以填写所有 OTP 字段后获得响应,您可以在此处编写自己的逻辑来使用填充的数字。
otpView.onFillDigits = { number in
print("input number is \(number)")
}
- 最终,设置一切完成后,调用一次渲染方法。
otpView.render()
作者
穆希特·库马尔
许可证
MKOtpView 可在 MIT 许可下使用。更多信息请参阅 LICENSE 文件。