PKSecurePin 2.0

PKSecurePin 2.0

Praveen Kumar Shrivastav 维护。




PKSecurePin

用 Swift 编写的优雅安全的动态输入 PIN

Platform Language License

功能

  • 易于使用
  • 基于配置的动态 PIN,有或没有确认 PIN
  • 只接受数字作为输入
  • 限制每次只能输入一个数字
  • 每次输入后自动跳转到下一个输入
  • 删除时自动跳转到上一个输入
  • 限制输入或选择其他 PIN,无需输入当前 PIN 的数字

Screenshot

Screenshot

安装

CocoaPods

在您的 Podfile

pod "PKSecurePin"

手动

将包含两个 Swift 文件的整个 PKSecurePin 文件夹复制到您的项目中

cp -rf PKSecurePin/ <to_your_project_dir>

使用说明

            // adopt the protocol
            class ViewController: UIViewController, UIPopoverPresentationControllerDelegate, PKSecurePinControllerDelegate
            
            // create an instance of PKSecurePinViewController, with how many PIN, OTP or confirmation, position from top
            //NOTE: Please specify the correct value for topPos for the PIN text field w.r.t. to iPad & iPhone
            var pinViewC = PKSecurePinViewController.init(numberOfPins: 6, withconfirmation: true, topPos: 230)
            
            // PKSecurePinControllerDelegate methods implementation
            func didFinishSecurePin(pinValue: String) {
                //show the message if you want to display on success, else comment the below line
                pinViewC.showMessage(PKSecurePinError(errorString:"Success", errorCode: 200, errorIsHidden: false))
                //Go ahead with the business logic which you want to achieve with the PIN
            }
            
            // set the background color for PIN controller
            pinViewC.view.backgroundColor = UIColor.white
            
            //set the delegate
            pinViewC.delegate = self

            // create the pin navigation controller
            let pinNav = UINavigationController(rootViewController: pinViewC)

            // set the presentation style
            pinNav.modalPresentationStyle = .popover

            //pinview controller position
            pinViewC.preferredContentSize = CGSize(width: UIScreen.main.bounds.width * 0.5, height: 200)

            // create an instance for popover
            let popover = pinNav.popoverPresentationController
            popover?.permittedArrowDirections = UIPopoverArrowDirection(rawValue: 0)
            popover?.sourceView = self.view

            //popover position
            popover?.sourceRect = CGRect(x: UIScreen.main.bounds.width * 0.5 - UIScreen.main.bounds.width * 0.25, y: UIScreen.main.bounds.height * 0.5 - 100, width: UIScreen.main.bounds.width * 0.5, height: 200)

            //present the pin navigation controller
            self.present(pinNav, animated: true, completion: nil)