设置TextFiled输入长度限制

时间:2023-01-03 19:19:38

#pragma mark - 显示超过11位不让输入

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{

if (textField == _nameTextFiled) {

int maxLength = 11;

NSString * str = textField.text;

if (textField.text.length>=11) {

textField.text = [str substringToIndex:maxLength-1];

}

}

return YES;

}