简体   繁体   中英

How to hide TEXT in TextField while clicking outside of TextField in Swift?

4(Swift4) I am trying to hide the TextField's text after I end editing the TextField , I tried doing this :

textField.isHidden = true

But it's job is to hide the TextField , what I want to do is that hide TEXT of the textField after Tapping outside the textField..

EDIT : I want to hide it, I don't want asterisk , I want the text to be invisible and when I click on textField again it should appear the written text again

I tried this :

textField.text.isHidden = true

It gives me error if I do this way.

Your time and help will be highly appreciated! Thank You!

You need to pack the text inside another variable

textContent = textField.text
textField.text = ""

if you want to hide the content like password set

textField.isSecureTextEntry = true

//

var textContent = ""

func textFieldDidEndEditing(_ textField: UITextField) {

    textContent = textField.text!

    textField.text = ""
}

func textFieldDidBeginEditing(_ textField: UITextField) {

    textField.text = textContent

}

Take textfield text into a variable and make textfield empty.

var textFieldText = textfield.text
textField.text = ""

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM