I'm having issues with toggling the secureEntry
property on UITextField
. When the property is toggled, the characters are resized, but the cursor stays in the wrong place:
I'm having issues with toggling the secureEntry
property on UITextField
. When the property is toggled, the characters are resized, but the cursor stays in the wrong place:
Here is my workaround:
textField.secureTextEntry = YES;
UITextRange *textRange = textField.selectedTextRange;
textField.selectedTextRange = nil;
textField.selectedTextRange = textRange;
Disable and then Enable the UITextField also help, but it will suddenly change my soft keyboard from one to another
After setting textField secureEntry
property NO
, you need to call becomeFirstResponder
method its works for me...
Try this
textField.secureTextEntry = NO;
if (textField.isFirstResponder){
[textField becomeFirstResponder];
}
Both are working for Swift 4
self.isSecureTextEntry = false
if textField.isFirstResponder {
textField.becomeFirstResponder()
textField.layoutIfNeeded()
}
I had to add textField.layoutIfNeeded()
that it's working for Swift or use
let textRange = self.selectedTextRange
self.selectedTextRange = nil;
self.selectedTextRange = textRange
For Swift 4
@objc func tapOnLeftIcon(gesture: UITapGestureRecognizer) {
let textRange = textField.selectedTextRange
textField.isSecureTextEntry = !textField.isSecureTextEntry
textField.selectedTextRange = nil
textField.selectedTextRange = textRange
}