最佳答案
下面是一个将您的 passwordTextField
点转换为“*”的示例代码,您可以修改此代码以使用您拥有的任何自定义字体中的自定义字符来给出红心:
@IBOutlet weak var passwordTextField: UITextField!
var passwordText = ""
func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
if textField == passwordTextField {
var hashPassword = String()
let newChar = string.first
let offsetToUpdate = passwordText.index(passwordText.startIndex, offsetBy: range.location)
if string == "" {
passwordText.remove(at: offsetToUpdate)
return true
}
else { passwordText.insert(newChar!, at: offsetToUpdate) }
for _ in 0..<passwordText.count { hashPassword += "*" }
textField.text = hashPassword
return false
}
return true
}
关于ios - 如何在 Swift 中自定义安全文本字段点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62047404/