如何在iOS Swift中将点更改为密码字段中的另一个字符 [英] How can I change the dots to another character on password field in iOS Swift
本文介绍了如何在iOS Swift中将点更改为密码字段中的另一个字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个文本字段,我想在隐藏密码时将默认点字符替换为其他字符。
有没有办法轻松做到这一点?
I have a Text Field and I would like to replace the default dot character to something else when the password is hidden. Is there any way to do this easily?
推荐答案
这里有2个选项:
- 使用没有安全输入选项的普通文本字段。当用户输入字符时,将其保存为字符串变量,并在文本字段中将其替换为您想要呈现的字符而不是项目符号。
这是代码(将密码显示为$$$$):
Here's the code (will show the password as $$$$):
var password: String = ""
func textField(textField: UITextField, shouldChangeCharactersInRange range: NSRange, replacementString string: String) -> Bool
{
password = password+string
textField.text = textField.text+"$"
println("\(password)")
return false
}
- check out the answers here: UITextField secureTextEntry bullets with a custom font?
这篇关于如何在iOS Swift中将点更改为密码字段中的另一个字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文