2015-11-04 72 views

回答

0

stackoverflow提供了一個工作的搜索引擎,但無論如何,在這裏你是答案。

做相同,但與false代替true

Obscure a UITextField password

順便說一句,確保用戶知道他做什麼時,揭示了安全的文本。

2

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 –