iOS development-Implement TextView hint text and enter word limit

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.