BT-OtpView 0.1.3

BT-OtpView 0.1.3

OmarAhmed TarekAhmed Tarek 维护。



  • 作者
  • Baianat

BT-OtpView

适用于 iOS 的一个现成的四位一次性密码视图。

快速入门

1- 将视图对象从对象库拖放到您的 Storyboard 中。

2- 在身份检查器中将视图的类设置为 OtpView。将它的模块属性设置为 BT_OtpView

3- 在您的视图控制器头文件中添加 import BT_OtpView

4- 在相应的视图控制器中创建一个输出口。

  @IBOutlet weak var otpView: OtpView!

5- 设置 otpView 的代理并实现 OtpViewDelegate

   
override func viewDidLoad() {
      ...
      otpView.delegate = self
}


extension ViewController : OtpViewDelegate {
  
  func shouldReceive(otpCode code: String, at otpView: OtpView) -> Bool {
      // code is the 4-digit code entered
      return true
}
  
}

shouldReceive(otpCode code: String, at otpView: OtpView) 会在输入四位代码时自动调用。

注意

  • shouldReceive : 此函数返回布尔值。如果输入四位代码,返回 true 会关闭键盘,否则返回 false。

  • 或者,您可以按以下方式访问代码。

      otpView.verificationCode  

    自定义

    您可以自定义 OtpView 以下属性:

属性 类型 默认值
defaultBorderColor UIColor .gray
focusedBorderColor UIColor .black
cornerRadius CGFloat 16.0
borderWidth CGFloat 1.0
defaultFillColor UIColor .clear
focusedFillColor UIColor .clear
hideCursor Bool true
isSecuredTextEntry Bool fales
onlyNumbers Bool true
placeHolder String ""
textColor UIColor .black
font UIFont nil -истемный défaut

您只需将 OtpView 上的 decorator 属性设置如下。

      otpView.decorator = OtpViewDecorator(
        defaultBorderColor: .gray,
        focusedBorderColor: .black,
        cornerRadius: 8,
        borderWidth: 1,
        defaultFillColor: .clear,
        focusedFillColor: .clear,
        hideCursor: true,
        isSecuredTextEntry: false,
        onlyNumbers: true,
        placeHolder: "*",
        textColor: .brown,
        font: UIFont.boldSystemFont(ofSize: 24)
      )

安装

要安装 OtpView,只需在您的 Podfile 中添加以下行

pod 'BT-OtpView'

许可证

BT-OtpView 在 MIT 许可证下可用。有关更多信息,请参阅 LICENSE 文件。