How do you obscure text in a password field in an iPhone Application?

IosObjective CIphoneUitextfield

Ios Problem Overview


I have a password field in my application (UITextField). When user enters text in the field, I want it to display * instead of the text they entered.

I have tried using the UIControlEventEditingDidEnd of UITextField but it only shows one * at the end when editing but I want it to display the *s as soon as any text is entered, like in any online email password field. How can I get the desired behavior?

Ios Solutions


Solution 1 - Ios

I don't really understand your question, but I'm guessing you want a UITextField which displays dots for the characters, which every password field on the iPhone does. For this, you want to set the secureTextEntry property of that UITextField (UITextField has such a property because it conforms to the UITextInputTraits protocol) to YES:

textfield.secureTextEntry = YES;

Solution 2 - Ios

You can also set this in Interface Builder. Select your text field, and check the "secure" setting in the inspector.

secure setting in Interface Builder

Solution 3 - Ios

You can add a key path secureTextEntry of type Boolean and tick it in the User defined runtime attributes in the Identity Inspector.

enter image description here

Solution 4 - Ios

If you are using the latest version of Xcode, (version 9), click on the UITextField that you want to set the input as password, then click on the attributes inspector and check "Secure Text Entry".

Solution 5 - Ios

Swift 3.3

textfield.isSecureTextEntry = true

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionjaynaiPhoneView Question on Stackoverflow
Solution 1 - IosdrvdijkView Answer on Stackoverflow
Solution 2 - IosNathaniel MartinView Answer on Stackoverflow
Solution 3 - IosVivekanandanView Answer on Stackoverflow
Solution 4 - IosDonnaView Answer on Stackoverflow
Solution 5 - IosMike.RView Answer on Stackoverflow