数字とピリオドのみを入力できるUITextFieldがあります"、"これが作成方法です。
#define NUMBERS @"0123456789"
#define NUMBERSPERIOD @"0123456789,"
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
NSCharacterSet *cs;
NSString *filtered;
// Check for period
if ([textFieled.text rangeOfString:@","].location == NSNotFound) {
cs = [[NSCharacterSet characterSetWithCharactersInString:NUMBERSPERIOD] invertedSet];
filtered = [[string componentsSeparatedByCharactersInSet:cs] componentsJoinedByString:@""];
return [string isEqualToString:filtered];
}
// Period is in use
cs = [[NSCharacterSet characterSetWithCharactersInString:NUMBERS] invertedSet];
filtered = [[string componentsSeparatedByCharactersInSet:cs] componentsJoinedByString:@""];
return [string isEqualToString:filtered];
}
ここで、「、」の後に入力する桁を2桁に制限したいと思います。これを行う方法がわかりませんか?