Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I change the dots to another character on password field in 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?

like image 256
Zsolt Papp Avatar asked May 22 '15 18:05

Zsolt Papp


People also ask

Why are there passwords in dots?

What Are The Dots When You Type In Your Password? The dots you see when you type in your passwords are called “masking.” The purpose of the dots is to hide your password as you type each letter. Each dot represents a character you type, but that is the only thing known about the password.

How do you make a text field non editable in Swift?

How do you make a text field Uneditable in Swift? Within code: textfield. enable = false.


1 Answers

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?
like image 110
Ron.Kliffer Avatar answered Sep 29 '22 10:09

Ron.Kliffer