iOS UITextField设置金额(钱数)输入框
2016-03-16 19:38
441 查看
1.定义
#define myDotNumbers @"0123456789.\n"#define myNumbers @"0123456789\n"
2.UITextField
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString*)string {
NSCharacterSet *cs;
NSUInteger nDotLoc = [textField.textrangeOfString:@"."].location;
if (NSNotFound == nDotLoc &&0 != range.location) {
cs = [[NSCharacterSetcharacterSetWithCharactersInString:myDotNumbers]invertedSet];
}
else {
cs = [[NSCharacterSetcharacterSetWithCharactersInString:myNumbers]invertedSet];
}
NSString *filtered = [[stringcomponentsSeparatedByCharactersInSet:cs]
componentsJoinedByString:@""];
BOOL basicTest = [stringisEqualToString:filtered];
if (!basicTest) {
returnNO;
}
if (NSNotFound != nDotLoc && range.location > nDotLoc +3) {
returnNO;
}
returnYES;
}
相关文章推荐
- UITextfield属性(初级篇)
- UI界面传值
- Customize UIView &UITextField
- iOS自学笔记之UISwitch和UITextField
- UITextField使用代理获取已输入的内容
- 修改TextField的Placeholder属性的字体大小,颜色
- NSMutableAttributedString文本样式设置以及富文本展示
- UIScrollView内容偏移的问题
- Objective-C: UIKit:UITextFiled、UIAlertController(警告框、操作表)、
- OC-XIB使用&UITextField
- OC-UITextField
- XIB中设置UITextField的高度
- iOS--页面跳转(UITableView)
- NGUI中打字效果TypewriterEffect的一个BUG
- POJ 2229 Ultra-QuickSort 归并排序求逆序数
- Number Sequence (HDU_1711) KMP
- build模式小例子
- [ShareSDK] QuickIntegrater.jar文件各种打不开
- UITextField - 解决键盘遮住View & 密文设定 & 实例
- 今天遇到 Request failed: method not allowed (405)。 错误,特此在网上翻了翻