Here\'s what I\'ve got:
@IBOutlet weak var password: NSSecureTextField!
@IBOutlet weak var shwpswd: NSButton! //Checkbox
@IBOutlet weak var pswdcell: NSSecureTe
You can accomplish what you want adding a second text field in top of your secure field. Add an IBAction to your check box to switch your fields isHidden property and copy the other textField stringValue and make it the first responder. Your implementation should look like something like this:
import Cocoa
class ViewController: NSViewController {
@IBOutlet weak var password: NSSecureTextField!
@IBOutlet weak var showPassword: NSTextField!
@IBOutlet weak var shwpswd: NSButton!
override func viewDidLoad() {
super.viewDidLoad()
shwpswd.state = .off
showPassword.isHidden = true
}
override func viewDidAppear() {
super.viewDidAppear()
password.window?.makeFirstResponder(password)
}
@IBAction func showHidePassword(_ sender: NSButton) {
showPassword.isHidden = !showPassword.isHidden
password.isHidden = !password.isHidden
if !showPassword.isHidden {
showPassword.stringValue = password.stringValue
showPassword.becomeFirstResponder()
} else {
password.stringValue = showPassword.stringValue
password.becomeFirstResponder()
}
}
}
show/hide password sample