Make a secure text field in iOS:
-(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
const char * _char;
_char = [string cStringUsingEncoding:NSUTF8StringEncoding];
int isBackSpace = isBackSpace = strcmp(_char, "\b");
if (isBackSpace == -8)
{
NSMutableString *text = [txtPassword.text mutableCopy];
if (range.length > 0) {
[text deleteCharactersInRange:range];
}
if (range.length == 0 && range.location != 0)
{
NSRange backward = NSMakeRange(range.location - 1, 1);
[text deleteCharactersInRange:backward];
}
txtPassword.text = text;
return YES;
}
pass = [pass stringByAppendingString:[NSString stringWithFormat:@"%s",_char]];
passStar = [passStar stringByAppendingString:@"*"];
txtPassword.text = passStar;
NSLog(@"text is %@",pass);
return YES;
}
No comments:
Post a Comment