Implement word count control and limit, and show the current input string length, as well as the button's click Status, the code is as follows:
1, setting up the proxy
@interface Fkviewcontroller () <UITextViewDelegate>** ** *STRINGLENGHTLAB;
2, set the initial state
- (void) viewdidload {[Super viewdidload]; //Do any additional setup after loading the view from its nib.Self.view.backgroundColor=BackgroundColor; Self.navigationController.navigationBarHidden=YES; Customnavigationbar*nav = [[Customnavigationbar alloc]initwithframe:cgrectmake (0,0, Kscreenw, Navheight) Withtitle:@"View Feedback"Withleftbtnhidden:no Withrightbtn:yes]; Nav.Delegate=Self ; [Self.view Addsubview:nav]; Self. Fktextview.Delegate=Self ; Self.descLab.userInteractionEnabled=NO; Self.sendBtn.userInteractionEnabled=NO; Self.sendBtn.backgroundColor=[Uicolor Lightgraycolor];}
3, the implementation of proxy method
-(void) Textviewdidchange: (Uitextview *) textview{Self.descLab.hidden=YES; Self.sendBtn.userInteractionEnabled=YES; Self.sendBtn.backgroundColor=Maincolor; //real-time display of wordsSelf.stringlenghtLab.text = [NSString stringWithFormat:@"%ld/100",(Long) TextView.text.length]; //Word Limit if(TextView.text.length >= -) {Textview.text= [Textview.text Substringtoindex: -]; } //Cancel the run-click permission and display the text if(TextView.text.length = =0) {Self.descLab.hidden=NO; Self.sendBtn.userInteractionEnabled=NO; Self.sendBtn.backgroundColor=[Uicolor Lightgraycolor]; }}
The string length is 0 o'clock, the button returns to the initial state, when there are input characters, is displayed as clickable state, very simple, only for recording!
iOS development-Implement TextView hint text and enter word limit