1. 程式人生 > >iOS開發—Swift實現支付密碼彈窗

iOS開發—Swift實現支付密碼彈窗

Swift實現支付密碼彈窗

輸入支付密碼彈窗簡單實現,類似支付寶。

主要程式碼檔案

  • popPayPwdView//支付密碼彈窗實現
  • CodeTextField//防止textField出現複製黏貼

使用方法:

    //需要使用支付彈窗
    @IBAction func inputPwdBtnPressed(sender: UIButton) {
        popPayView = popPayPwdView()
        popPayView!.delegate = self
        popPayView!.pop()
    }
    //支付密碼
var yourPayCode = "111111" //popPayDelegate、匹配支付密碼,最好從服務端匹配支付密碼 func compareCode(payCode: String) { if payCode == yourPayCode { print("inputPwd successed") let con = UIViewController() con.title = "Successed" con.view.backgroundColor =
UIColor.redColor() self.navigationController?.pushViewController(con, animated: true) } else { if #available(iOS 8.0, *) { let alertController = UIAlertController(title: nil, message: "PassWord Error", preferredStyle: .Alert) let
cancelAction = UIAlertAction(title: "OK", style: .Cancel) { (action) in } alertController.addAction(cancelAction) self.presentViewController(alertController, animated: true) { } } else { let errorAlertView = UIAlertView(title: "PassWord Error", message: "Please try again", delegate: self, cancelButtonTitle: "Ok") errorAlertView.show() } } }
  • 具體實現支付彈窗請移步git^.^
  • 實現中如有不足之處,歡迎大家留言^.^