在UITextfield代理shouldChangeCharactersInRange或者给UITextfield添加事件(UIControlEventEditingChanged)的方法中添加以下代码:
NSCharacterSet *characterSet = [[NSCharacterSet characterSetWithCharactersInString:@"0123456789."] invertedSet];//设置过滤的集合
NSString *filtered = [[sender.text componentsSeparatedByCharactersInSet:characterSet] componentsJoinedByString:@""];//过滤
sender.text = filtered;//赋值