限制 UITextField 的输入长度

清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range 
                            replacementString:(NSString *)string 
{
    //Check that response should be a maximum 5 characters
    if ([string length] > 0) {
        return [textField.text length] < 5;
    }
    return YES;
}

-(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
    if([string length]>0{
        return [textField.text length]<5;  //这里报错,textField没有 text属性?
    }
       return YES;
}