How do I stop UITextField Secure text showing characters

偶尔善良 提交于 2019-12-24 12:07:42

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!