之前在cocoachina看到一篇文章http://www.cocoachina.com/ios/20160106/14889.html,挺实用的,非常好用,肯定以后可以遇到,登录的时候肯定能遇到-(void)textFieldTextDidChanged:(UITextField*)sender{NSString*tempString=sender.text;if(sender.markedTextRange==nil&&tempString.length>kMaxLength){sender.text=[tempStringsubstringToIndex:kMaxLength];[sender.undoManagerremoveAllActions];}}