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