设置TextFiled输入长度限制

#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;

}

原文地址:https://www.cnblogs.com/block123/p/4947658.html