How can I change the dots to another character on password field in iOS Swift

后端 未结 3 473
别跟我提以往
别跟我提以往 2021-01-02 17:13

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?

3条回答
  •  一向
    一向 (楼主)
    2021-01-02 18:09

    2 options here:

    1. Use a normal textfield without the secure input option. When a user enters a character, save it to a string variable, and replace it in the textfield with the character you wish to present instead of the bullets.

    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
    }
    
    1. check out the answers here: UITextField secureTextEntry bullets with a custom font?

提交回复
热议问题