Swift实现支付密码弹窗
输入支付密码弹窗简单实现,类似支付宝。
- swift语法
- 输入支付密码弹窗实现
- 项目地址:https://github.com/yaoyunheng/Swift-PayPasswordDemo
主要代码文件
- 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^.^
- 实现中如有不足之处,欢迎大家留言^.^