Is there a clever way to let the user switch between hide and view password in an ios/iphone UITextField where the user can enter a password and would have the option of either hide it or view it. thanks in advance.
With iCloud Keychain, you can keep your passwords and other secure information updated across your devices. iCloud Keychain remembers things, so that you don't have to. It auto-fills your information—like your Safari usernames and passwords, credit cards, and Wi-Fi passwords on any device that you approve.
Simply setting
.secureTextEntry = YES
wont work I think due to a bug (or a feature), if the textField has focus.
Use something like this to make it work also if the textField is currently firstResponder
-(void) toggleTextFieldSecureEntry: (UITextField*) textField {
BOOL isFirstResponder = textField.isFirstResponder; //store whether textfield is firstResponder
if (isFirstResponder) [textField resignFirstResponder]; //resign first responder if needed, so that setting the attribute to YES works
textField.secureTextEntry = !textField.secureTextEntry; //change the secureText attribute to opposite
if (isFirstResponder) [self.textField becomeFirstResponder]; //give the field focus again, if it was first responder initially
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With