- (void)viewDidLoad {
[superviewDidLoad];
[self.textFieldaddTarget:selfaction:@selector(textFieldChange:)forControlEvents:UIControlEventEditingChanged];
self.textField.keyboardType=UIKeyboardTypeNumberPad;
}
#pragma mark -输入框实时更新
- (void)textFieldChange:(UITextField*)textField
{
self.resultLab.text= [selfjointWithString:self.textField.text];
}
#pragma mark -拼接成中间有空格的字符串
- (NSString*)jointWithString:(NSString*)str{
NSString*getString =@"";
inta = (int)str.length/4;
intb = (int)str.length%4;
intc = a;
if(b>0){
c = a+1;
}else{
c = a;
}
for(inti =0; i
NSString*string =@"";
if(i == (c-1)){
if(b>0){
string = [strsubstringWithRange:NSMakeRange(4*(c-1), b)];
}else{
string = [strsubstringWithRange:NSMakeRange(4*i,4)];
}
}else{
string = [strsubstringWithRange:NSMakeRange(4*i,4)];
}
getString = [NSStringstringWithFormat:@"%@ %@",getString,string];
}
returngetString;
}