- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
NSString *valueStr = nil;
if (string.length > 0)
{
if (textField.text.length >6) {
return NO;
}
else {
NSArray *tmp = [string componentsSeparatedByString:@"."];//分割字符串
if (tmp.count > 1) {
return NO;
}
NSString *newString = nil;
newString = [string stringByReplacingOccurrencesOfRegex:@"[^0-9.]" withString:@""];
if (newString == @"") {
return NO;
}
valueStr = [NSString stringWithFormat:@"%.0f",[textField.text doubleValue]*10];
}
textField.text = [valueStr stringByAppendingFormat:@"."];
}
else {
valueStr = [NSString stringWithFormat:@"%.2f",[textField.text doubleValue]/10];
textField.text = valueStr;
}
return YES;
}
IOS TextField 根据输入,分割整数与小数部分
最新推荐文章于 2017-10-25 14:44:58 发布