Arya
Arya

Reputation: 13

I want to convert textfield text into secure text like password when editing end(when user goes to next field) in swift

I want to convert textfield text into secure text like password when editing end(basically when user goes to next field) in swift.

Upvotes: 1

Views: 865

Answers (2)

Lumialxk
Lumialxk

Reputation: 6369

1.Set that UITextField secure input.

secureField.isSecureTextEntry = true

2.Or set delegate and change its text when editing begins or ends.

secureField.delegate = self

func textFieldDidEndEditing(_ textField: UITextField) {
    if secureField == textField {
        textField.isSecureTextEntry = true
    }
}

func textFieldDidBeginEditing(_ textField: UITextField) {
    if secureField == textField {
        textField.isSecureTextEntry = false
    }
}

Upvotes: 1

Sapana Ranipa
Sapana Ranipa

Reputation: 919

Delegate Your textfield with view

and set this two methods

func textFieldDidBeginEditing(_ textField: UITextField) {
    if textField==self.txtEmail
    {
        self.txtEmail.isSecureTextEntry = false
    }
}
func textFieldDidEndEditing(_ textField: UITextField) {
    if textField==self.txtEmail
    {
        self.txtEmail.isSecureTextEntry = true
    }

}

Upvotes: 1

Related Questions