-3

How do I reveal the passcode dots in swift, so then the user can see their password by clicking a button. Thanks Tyge

pnuts
  • 58,317
  • 11
  • 87
  • 139
Tyge
  • 229
  • 1
  • 2
  • 6

2 Answers2

2

TextField has a property called secureTextEntry. All you need is to connect an outlet to your textfield and toggle secureTextEntry:

import UIKit

class ViewController: UIViewController {

    @IBOutlet weak var passwordField: UITextField!

    override func viewDidLoad() {
        super.viewDidLoad()
        passwordField.secureTextEntry = true
        // Do any additional setup after loading the view, typically from a nib.
    }
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    @IBAction func showHide(sender: UIButton) {
        passwordField.secureTextEntry = !passwordField.secureTextEntry
        sender.setTitle({passwordField.secureTextEntry ? "Show":"Hide"}(), forState: .Normal)
    }
}
Leo Dabus
  • 229,809
  • 59
  • 489
  • 571
0

stackoverflow provides a working search engine, but anyway here you is the answer.

Do the same, but with false instead of true

Obscure a UITextField password

By the way make sure that the user knows what he does when reveal the secure text.

Community
  • 1
  • 1
awph
  • 566
  • 6
  • 15