本篇文章是使用了reactcoca自动化布局的:
再输入手机号的时候,自动加空格进行分割
- (void)editePhone{
[[self.phoneTextField.rac_textSignal filter:^BOOL(NSString * _Nullable value) {
if (self.phoneNumber.length < value.length) {
if (value.length == 4 || value.length == 9) {
NSString *occString = [value substringFromIndex:value.length - 1];
NSString *replaceString = [NSString stringWithFormat:@" %@", occString];
self.phoneTextField.text = [[value substringToIndex:value.length - 1] stringByAppendingString:replaceString];
}
}
else {
if (value.length == 4 || value.length == 9) {
if (value.length == self.phoneTextField.text.length) {
self.phoneTextField.text = [value substringToIndex:value.length - 1];
}
}
}
return value.length > 13;
}]
subscribeNext:^(NSString * _Nullable x) {
NSLog(@"%@", x);
self.phoneTextField.text = [x substringToIndex:13];
}];
}