UITextField相关设置

设置UITextField的最大长度

协议:
设置代理:textField.delegate = self;
执行方法:


- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
    if(textField.text.length+string.length>=17&&string.length>0) {
        textField.text=[[textField.text stringByAppendingString:string] substringToIndex:17];
        return NO;
    }
    return YES;
}

你可能感兴趣的:(UITextField相关设置)