Toggling UITextField to show and hide in Swift

Deadly 提交于 2019-12-04 05:06:32

Use this to set when you want the UITextField hidden or visible depending on your application structure

You can do it this way to make the field visible:

myTextField.isHidden = false

and this way to make it hidden:

myTextField.isHidden = true

Updated for Swift :

Used below simple code :

// UIButtonOutlet

@IBOutlet var confirmPassTextField: UITextField!
@IBOutlet var confirmPassButton: UIButton!

//IBAction Method

@IBAction func actionOnConfirmButton(_ sender: Any) {
    if (confirmPassTextField.isSecureTextEntry == true){
        confirmPassTextField.isSecureTextEntry = false
        confirmPassButton.setImage(UIImage(named: "show_pass"), for: .normal)
    }else{
        confirmPassButton.setImage(UIImage(named: "hide_pass"), for: .normal)
        confirmPassTextField.isSecureTextEntry = true
    }
}

Note: "show_pass" and "hide_pass" - UIImage Name

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!