<span style="font-family:Comic Sans MS;font-size:18px;">这个键盘并没有对小数点进行限制,如果自定义键盘会比较麻烦 如以pad键盘为例也需要较多的代码 只需要点的完美解决方式。不喜勿喷!</span>
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
NSCharacterSet *nonNumberSet = [[NSCharacterSet characterSetWithCharactersInString:@"0123456789."]invertedSet];
// allow backspace
if (range.length > 0 && [string length] == 0) {
return YES;
}
// do not allow . at the beggining
if (range.location == 0 && [string isEqualToString:@"."]) {
return NO;
}
NSString *currentText = textField.text; //当前确定的那个输入框
if ([string isEqualToString:@"."]&&[currentText rangeOfString:@"." options:NSBackwardsSearch].length =