设置UITextField的最大长度
协议:<UITextFieldDelegate>
设置代理: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;
}