I know that its possible to make UITextfield operate in a password mode by using the following :
textfield.secureTextEntry = YES;
This changes all characters entered by the user into '*'. However, the last character entered flashes up for about half a second. I understand that this is standard behavior.
Is there any way of stopping this and keeping the characters entered completely obscured?
To achieve this, Im thinking of subclassing UITextField
and then overriding drawTextInRect:rect
But I would welcome any other suggestions.
A Boolean value that indicates whether a text object disables copying, and in some cases, prevents recording/broadcasting and also hides the text.
You can do this:
UITextFieldTextDidChangeNotification
This code works, it's kind of ugly, though, it can probably be optimized.
- (void)viewDidLoad
{
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(keyPressed:) name: UITextFieldTextDidChangeNotification object: nil];
}
- (void) keyPressed: (NSNotification *) notification {
if(!self.password)
self.password = @"";
NSString* fieldText = [notification.object valueForKey:@"text"];
NSString* lastChar = [fieldText substringFromIndex:fieldText.length-1];
if(self.password.length>fieldText.length)
self.password = [self.password substringToIndex:self.password.length-1];
else
self.password = [NSString stringWithFormat:@"%@%@", self.password, lastChar];
NSString* secret = @"";
for (int l = 0; l<self.password.length; l++) {
secret = [secret stringByAppendingString:@"*"];
}
self.textField.text = secret;
}
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