Commit 5db190e9 authored by Sandy's avatar Sandy

包装规格限制输入小数位数

parent c63ff51b
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
<key>CFBundlePackageType</key> <key>CFBundlePackageType</key>
<string>APPL</string> <string>APPL</string>
<key>CFBundleShortVersionString</key> <key>CFBundleShortVersionString</key>
<string>1.2.8</string> <string>1.2.9</string>
<key>CFBundleSignature</key> <key>CFBundleSignature</key>
<string>????</string> <string>????</string>
<key>CFBundleVersion</key> <key>CFBundleVersion</key>
......
...@@ -363,6 +363,7 @@ typedef enum : NSUInteger { ...@@ -363,6 +363,7 @@ typedef enum : NSUInteger {
label.left = textField.right+ 5; label.left = textField.right+ 5;
_measureUnitLabel = label; _measureUnitLabel = label;
textField.placeholder = @"输入包装规格"; textField.placeholder = @"输入包装规格";
textField.tag =111;
[textField addTarget:self action:@selector(textChange:) forControlEvents:UIControlEventAllEditingEvents]; [textField addTarget:self action:@selector(textChange:) forControlEvents:UIControlEventAllEditingEvents];
packageSpecification=textField;//包装规格 packageSpecification=textField;//包装规格
...@@ -455,6 +456,54 @@ typedef enum : NSUInteger { ...@@ -455,6 +456,54 @@ typedef enum : NSUInteger {
} }
} }
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
if (textField.tag != 111) {
return YES;
}
NSMutableString * futureString = [NSMutableString stringWithString:textField.text];
// kLOG(@"%@", futureString);
[futureString insertString:string atIndex:range.location];
// kLOG(@"----%@", futureString);
NSInteger flag = 0;
NSInteger pointNum = 0;//用于标记小数点的数量,只能有一个小数点
const NSInteger limited = 2;//限制小数点后面的位数
for (int i = (int)futureString.length - 1; i>=0; i--) {
if ([futureString characterAtIndex:i] == '.') {
pointNum++;
// kLOG(@"----->>>%ld",pointNum);
if (pointNum == 2) {
return NO;
}
}
}
for (int i = (int)futureString.length - 1; i>=0; i--) {
if ([futureString characterAtIndex:i] == '.') {
if (flag > limited) {
return NO;
}
break;
}
flag++;
}
return YES;
}
#pragma mark - textFiled事件 #pragma mark - textFiled事件
- (void)textChange:(UITextField *)textField{ - (void)textChange:(UITextField *)textField{
//包装规格和包装数量 //包装规格和包装数量
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment