iOS swift 输入密码(不显示)

    var newPassword = ""
    
        func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
        if var text = textField.text {
            if text.count > 0 {
                text.removeLast()
                text += "*"
                textField.text = text
            }
        }
        if string.count != 0 {
                newPassword += string
        }else {
            //按了删除
                newPassword.removeLast()
        }

        return true
    }
    
    func textFieldDidChangeSelection(_ textField: UITextField) {
        DispatchQueue.main.asyncAfter(deadline: DispatchTime.now()+0.5) {
            if var text = textField.text {
                if text.count > 0 {
                    text.removeLast()
                    text += "*"
                    textField.text = text
                }
            }
        }
        print(newPassword)
    }

相关博客:
Swift GCD 延时执行

相关推荐
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页