The above says it all- I have a UITextField set to secure, but want to give users the option to make it not secure (so they can see for sure what they typed if they are in a private area). However, suppose they hit the toggle by mistake, and want to change it back to secure mode? That does not work. I've tried everything - using -1 instead of YES, deleting the text and then putting it back. I'm at a total loss on other ideas. [Entered rdar://9781908]
EDIT: I believe this issue is fixed as of iOS5.
A Boolean value that indicates whether a text object disables copying, and in some cases, prevents recording/broadcasting and also hides the text.
It must be input-focus issue: when focused, UITextField can change only ON->OFF.
Try next trick to switch OFF->ON:
textField.enabled = NO; textField.secureTextEntry = YES; textField.enabled = YES; [textField becomeFirstResponder];
EDIT (dhoerl): In iOS 9.3, I found this works but there is a problem. If you enter say 3 characters in plain view, then switch to secure text, then type a character, the 3 pre-existing characters disappear. I tried all kinds of trick to clear, then reset the text without success. I finally tried just playing with the control by cutting and pasting - pasting into the newly-switched-to-secure-mode worked great. So I emulated it in code, and now it all works fine - no need to play with the responder either. Here is what I finally ended up with:
if textview should go into secure mode and the textfield is not empty { textField.text = "" textField.secureTextEntry = true UIPasteboard.generalPasteboard().string = password textField.paste(self) UIPasteboard.generalPasteboard().string = "" }
I'd prefer to not have to do this paste, but if you want it seamless this is the only way I can find to do it.
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