标签:
使用TextFieldDelegate中的方法:
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string;
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{ if([string isEqualToString:@"\n"]){ //按回车关闭键盘 [textField resignFirstResponder]; return NO; }else if (string.length == 0){ //判断是不是删除键 return YES; }else if(self.nicknameText.text.length >= 10){ //输入的字符个数大于10,则无法继续输入,返回NO表示禁止输入 return NO; }else{ return YES; } }
标签:
原文地址:http://www.cnblogs.com/overcode/p/4385737.html