用这个 UIControlEventEditingChanged 事件绑定
#pragma mark - textField -代理
- (void)textFieldDidChange:(UITextField *)text
{
NSLog(@"%@",text.text);
NSString * str = [text.text stringByReplacingOccurrencesOfString:@" " withString:@""];
if (str.length >3&&text.text.length >3) {
text.text = [NSString stringWithFormat:@"%@ %@",[str substringWithRange:NSMakeRange(0, 3)],[str substringWithRange:NSMakeRange(3,str.length - 3)]];
}
if (text.text.length == 4 &&str.length ==3) {
text.text = [NSString stringWithFormat:@"%@",[str substringWithRange:NSMakeRange(0, 3)]];
}
if (str.length >7&&text.text.length >7) {
text.text = [NSString stringWithFormat:@"%@ %@",[text.text substringWithRange:NSMakeRange(0, 8)],[text.text substringWithRange:NSMakeRange(8, text.text.length - 8)]];
}
if (str.length >11) {
text.text = [text.text substringWithRange:NSMakeRange(0, 13)];
}
// if (text.text.length == 8 &&str.length ==7) {
// text.text = [NSString stringWithFormat:@"%@",[str substringWithRange:NSMakeRange(0, 7)]];
// }
}
网友评论