Monitoring Uitextfield changes can add target to the Uicontroleventeditingchanged event.
We sometimes need to use this requirement: input box input text more than XX length, no longer allowed to enter other content!
The Uitextfield proxy method itself is unable to meet this requirement. (You can, of course, add placeholder to Uitextview to achieve the same requirements, not described here.) )
The sample code is as follows:
Uitextfield *textfield = [[Uitextfield alloc] Initwithframe:cgrectmake (20 . F, 100 . F, Cgrectgetwidth (self.view.frame)-40 . F, 30 .f)]; Textfield.backgroundcolor = [Uicolor Whitecolor]; Textfield.placeholder = @ " placeholder_ King // add uicontroleventeditingchanged Target event, you can monitor TextField content in real time and do some action [TextField addtarget:self Action: @selector (Textfielddidchange:) Forcontrolevents:uicontroleventeditingchanged];
-(void) Textfielddidchange: (Uitextfield *) TextField { // text input length > 6 o'clock, No longer allowed to enter other content nsmutablestring *tempstr = [nsmutablestring stringWithString:textField.text ]; if 6 ) { = Nsmakerange (61); [TempStr Deletecharactersinrange:range]; } = tempstr;}
Resources:
Portal One (Swift)
Portal Two (OC)
Monitor changes in Uitextfield