使用Swift显示密码点

使用Swift显示密码点,swift,ios8,swift2,ios9,Swift,Ios8,Swift2,Ios9,如何在swift中显示密码点,以便用户可以通过单击按钮查看其密码。 谢谢 Tygestackoverflow提供了一个可用的搜索引擎,但不管怎样,这里是答案 做同样的事,但是用假代替真 顺便说一句,请确保用户知道在显示安全文本时他会做什么。TextField有一个名为secureTextEntry的属性。您只需将插座连接到textfield并切换secureTextEntry: import UIKit class ViewController: UIViewController {

如何在swift中显示密码点,以便用户可以通过单击按钮查看其密码。 谢谢
Tyge

stackoverflow提供了一个可用的搜索引擎,但不管怎样,这里是答案

做同样的事,但是用假代替真


顺便说一句,请确保用户知道在显示安全文本时他会做什么。

TextField有一个名为secureTextEntry的属性。您只需将插座连接到textfield并切换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)
    }
}