【发布时间】:2015-11-04 23:25:30
【问题描述】:
如何快速显示密码点,以便用户可以通过单击按钮查看密码。 谢谢 类型
【问题讨论】:
如何快速显示密码点,以便用户可以通过单击按钮查看密码。 谢谢 类型
【问题讨论】:
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)
}
}
【讨论】:
stackoverflow 提供了一个有效的搜索引擎,但无论如何你就是答案。
做同样的事情,但使用false 而不是true
Obscure a UITextField password
顺便说一句,确保用户知道他在显示安全文本时做了什么。
【讨论】: