Secure Text .Echosbullets Not Working for Password Field

Secure text .echosbullets not working for password field

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.toggle()
password.isHidden.toggle()
if !showPassword.isHidden {
showPassword.stringValue = password.stringValue
showPassword.becomeFirstResponder()
} else {
password.stringValue = showPassword.stringValue
password.becomeFirstResponder()
}
}
}

show/hide password sample

How to focus on a text field when opening an application?

You seem to be not over-riding the viewDidAppear that belongs to your NSViewController, but you are adding a new function on it's own.

Try using:

override func viewDidAppear() {
// Though the default implementation does nothing as of now,
// it is always safe to have the call to the super function in place,
// in case you plan to add sub-classes in between.
super.viewDidAppear()

addDomain.window?.makeFirstResponder(addDomain)
}


Related Topics



Leave a reply



Submit