//进行文字的限制
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
if (string.length == 0) {
return YES;
}
NSInteger restrictionNum = 20;
if (textField == self.timeTextField) {
restrictionNum = 12;
}
else if(textField == self.moneyTextField)
{
restrictionNum = 9;
}
NSInteger existedLength = textField.text.length;
NSInteger selectedLength = range.length;
NSInteger replaceLength = string.length;
if (existedLength - selectedLength + replaceLength > restrictionNum) {
return NO;
}
return YES;
}
iOS UITextField限制字数
最新推荐文章于 2024-05-22 16:10:35 发布