- (BOOL)TextField:(Uitextfield *)TextField Shouldchangecharactersinrange:(Nsrange)Range replacementstring:(NSString *)String; {String is the character entered at this time TextField is the input box that is being entered returns Yes to change the value of the input box no oppositeIf ([StringIsequaltostring:@"\ n"])Press passing to change{ReturnYES;} NSString *Tobestring= [TextField.Text Stringbyreplacingcharactersinrange:Range withstring:String]; Get the contents of the input boxIf (Self.MyTextField==TextField)Determine if we want to limit the input box{If ([Tobestring length] > 20) { Pop-up warning if input box content is greater than 20TextField.Text= [Tobestring Substringtoindex:20];Uialertview *Alert= [[[UialertviewAlloc]Initwithtitle:NilMessage:@"More than the maximum number of words cannot be entered" Delegate:NilCancelbuttontitle:@"OK" Otherbuttontitles:nil nil] Autorelease];< Span class= "PLN" > [< Span class= "PLN" >alert show; No; } } return Yes; /span>
iOS TextField limit the amount of characters you can enter for a certain length