Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Secure UITextField text change to (*) asterisk character

How can I change a secure UITextField text (which is simply a bunch of dots) to (*) asterisk characters like in the image below?

enter image description here

like image 390
Tim Tuffley Avatar asked Jun 09 '13 04:06

Tim Tuffley


2 Answers

You can set it programmatically by

[textField setSecureTextEntry:YES];

or in IB (secured checkbox at the bottom)

enter image description here

like image 141
Anupdas Avatar answered Nov 19 '22 17:11

Anupdas


You could also try simply implementing your own "secure text field".

Simply create a normal, non-secure text field, and link it's "Editing Changed" action with a method in your view controller.

Then within that method you can take the new characters every time the text is changed, and add them to a private NSString property, and then set the textField's .text property to a string with just asterisks in it (or any other character if you prefer).

Update: as noted by hayesk below, this solution is no longer ideal, as the introduction of third-party keyboards exposes input on any non-secure text fields to the third-party application, risking them collecting that information, and/or adding it to the autocorrect database.

like image 42
Fateh Khalsa Avatar answered Nov 19 '22 16:11

Fateh Khalsa