1,输入的时候4位空一格。方法如下
else if([textField.text length] >= 4) {
textField.text=[self fourTextBlankB:textField.text];
}
-(NSString *)fourTextBlankB:(NSString *)text{
NSString *strLastFour = [text substringFromIndex:[text length] - 4];
NSRange whiteSpaceRange = [strLastFour rangeOfString:@" "];
if (whiteSpaceRange.location == NSNotFound) {
text = [text stringByAppendingString:@" "];
}
return text;
}
2,拿到全部卡号然后4位空一格
cell.mTextField.text= [FuCardUtils setCardNumberValue:responseData[@"cardNo"]];
/*银行卡卡号每4位空一个间隔*/
+(NSString *)setCardNumberValue:(NSString *)strCardNumber
{
NSMutableString *temp=[[[NSMutableString alloc] init] autorelease];
if(strCardNumber.length >=5){
for(int i=0;i<strCardNumber.length/4+1;i++){
if(strCardNumber.length%4!=0){
if(i<strCardNumber.length/4){
[temp appendString:[strCardNumber substringWithRange:NSMakeRange(0+4*i,4)]];
[temp appendString:@" "];
}else{
[temp appendString:[strCardNumber substringFromIndex:0+4*i]];
}
}else{
if(i<strCardNumber.length/4-1){
[temp appendString:[strCardNumber substringWithRange:NSMakeRange(0+4*i,4)]];
[temp appendString:@" "];
}else{
[temp appendString:[strCardNumber substringFromIndex:0+4*i]];
}
}
}
strCardNumber=[temp retain];
}else{
strCardNumber=[strCardNumber retain];
}
return [strCardNumber autorelease];
}