问题
I've enabled Secure text for my UITextField. At runtime when I type some text in I initially see the character before it turns to a bullet point. Is there a way to stop it showing the characters and having it as a bullet point as I type.
Is there something I need to add to
-(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
Has anyone got an example?
回答1:
That is the default behaviour of the UITextField
. So there's nothing much you can do about it. You can play with some kind of encryption on the coding side but on the view side, this behaviour will prevail.
回答2:
I dont know its good practice or not but following trick did it for me
-(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
NSString *editedString = [textField.text stringByReplacingCharactersInRange:range withString:string];
textField.text = editedString;
return NO;
}
来源:https://stackoverflow.com/questions/24531274/how-do-i-stop-uitextfield-secure-text-showing-characters