在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:@""]; } }
參考鏈接:
