在UITextfield中输入ABCD会得到A B C D这种字母之间的空格需要特殊的方法才能清除掉。
-(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string { NSString* newstring = [textField.text stringByReplacingCharactersInRange:range withString:string]; NSString *checker = [NSString stringWithFormat:@"%C", 8198]; // %C为大写 if ([newstring rangeOfString:checker].length) { newstring = [newstring stringByReplacingOccurrencesOfString:checker withString:@""]; } }
参考链接:
http://www.cocoachina.com/bbs/read.php?tid-135439.html
原文地址:https://www.cnblogs.com/wobuyayi/p/9706310.html
时间: 2024-10-30 23:07:34