使用Swift显示密码点

问题描述:

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

*提供了一个工作的搜索引擎,但无论如何,在这里你是答案。

做相同,但与false代替true

Obscure a UITextField password

顺便说一句,确保用户知道他做什么时,揭示了安全的文本。

TextField有一个名为secureTextEntry的属性。所有你需要的是一个出口连接到您的文本框和切换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) 
    } 
} 
+0

https://www.dropbox.com/s/3gyh7cd6lweo13n/passwordInput.zip?dl=0 –