关于TextField位数输入限制

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

{

    if(textField == self.codeField){

        NSInteger strLength = textField.text.length - range.length + string.length;

        return(strLength <= 1);

    }else if(textField == self.numberField){

        NSInteger strLength = textField.text.length - range.length + string.length;

        return(strLength <= 2);

    }else if(textField == self.extensionField){

        NSInteger strLength = textField.text.length - range.length + string.length;

        return(strLength <= 3);

    }

    return YES;

}

你可能感兴趣的:(关于TextField位数输入限制)