IOS Uitextview Limit Words

Source: Internet
Author: User



Uitextview input Box

    self . contenttv = [[uitextview alloc ] initwithframe : cgrectmake (0 , Lineviewone. Frame . origin . y +lineviewone. frame . size . height +1 , Self . view . frame . size . width , 160 )];

self. Contenttv . BackgroundColor = [uicolorwhitecolor];

self. Contenttv . TextAlignment = Nstextalignmentleft;

//self.contenttv.text = @ " What problem are you having in use?" can give us timely feedback oh ! ";

self. Contenttv . Font = [uifont systemfontofsize:14.0];

self. Contenttv . Keyboardtype =  Uikeyboardtypenamephonepad;

self. Contenttv . Clearsoninsertion =YES;

[Self. View addsubview:self. Contenttv];

Self. Contenttv. delegate =self;

    self . placehoderlabel = [[uilabel alloc ] initwithframe : CGRectMake (0 , 0 , self . contenttv . frame . size . width , 30 )];

    self . placehoderlabel Backgroundcolor = [ uicolor whitecolor ";

self. Placehoderlabel . text = @ " what problem are you having in use?" can give us timely feedback oh ! " ;

//self.placehoderlabel.alpha = 0.5;

//self.placehoderlabel.textalignment = nstextalignmentcenter;

    self . placehoderlabel font = [ uifont Systemfontofsize: 13.0 ];

[self. Contenttvaddsubview:self. Placehoderlabel];

#pragma mark-uitextviewdelegate

-(BOOL) TextView: (uitextview *) TextView shouldchangetextinrange: (nsrange) range Replacementtext: (nsstring *) text

{

nsstring *temp = [TextView. Text

stringbyreplacingcharactersinrange: Range

withstring: text];

nsinteger remaintextnum = +;

// Calculate how much text is left to enter

if (Range. location >=)

{

Remaintextnum =0;

        [ self showsimplealert: @" 100 " ];

self. Emailft . userinteractionenabled =NO;

return YES;

}

Else

{

nsstring * nstextcontent = temp;

nsinteger existtextnum = [nstextcontent length];

Remaintextnum =-existtextnum;

       self . label = [[uilabel alloc ] initwithframe : cgrectmake (Textview.frame . size . width -80 , TextView. frame . size . height -30 , 80 , 30 )];

self. label . TextAlignment = Nstextalignmentcenter;

[TextViewaddsubview:self. label];

self. label . BackgroundColor = [uicolorwhitecolor];

Self. label. text = [nsstringstringwithformat:@ "%ld/100", (long) Remaintextnum];

return YES;

}

}



When you type, the label shows how many words are left.


IOS Uitextview Limit Words

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.