Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to toggle a UITextField secure text entry (hide password) in Swift?

I currently have a UITextfield with an eye icon in it that when pressed is supposed to toggle the secure text entry on and off.

secure text entry

I know you can check mark the "secure text entry" box in the attributes inspector but how to do it so it toggles whenever the icon is pressed?

like image 857
SwiftyJD Avatar asked Jun 17 '16 04:06

SwiftyJD


People also ask

What is used to mask the password in Swift?

Or you can do it using code: Identifies whether the text object should hide the text being entered. This property is set to false by default. Setting this property to true creates a password-style text object, which hides the text being entered.

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.

What is secure text entry?

A Boolean value that indicates whether a text object disables copying, and in some cases, prevents recording/broadcasting and also hides the text.


1 Answers

Use this code,

iconClick is bool variable, or you need other condition check it,

var iconClick = true 

eye Action method:

@IBAction func iconAction(sender: AnyObject) {         if(iconClick == true) {             passwordTF.secureTextEntry = false         } else {             passwordTF.secureTextEntry = true         }          iconClick = !iconClick     } 

hope its helpful

like image 163
Iyyappan Ravi Avatar answered Sep 26 '22 18:09

Iyyappan Ravi