Reprint Source: http://blog.sina.com.cn/s/blog_693de6100101cmdw.html
Basic ideas:
Finish button: Release the keyboard by detecting the \ n line break feature.
Placeholder function: Write the text with a label, and then hide the label when it detects that the length is not 0. Because the input method has pinyin, so to add multiple judgments!! Advicemsg for TextView. How to use:
- Add <UITextViewDelegate> Agreements
- Set textview.delegate = self;
- Add Placeholderlabel and TextView, and modify the corresponding code
-(BOOL) TextView: (Uitextview *) TextView Shouldchangetextinrange: (nsrange) Range Replacementtext: (NSString *) Text {if([Text isequaltostring:@"\ n"]) {//"Done" detected[TextView Resignfirstresponder];//Release the keyboard returnNO; } if(advicemsg.text.length==0){//TextView length is 0 if([Text isequaltostring:@""]) {//determine if the key is deletedLabeltext.hidden=no;//Hide Text}Else{Labeltext.hidden=YES; } }Else{//textview length is not 0 if(advicemsg.text.length==1){//textview length is 1 times if([Text isequaltostring:@""]) {//determine if the key is deletedlabeltext.hidden=NO; }Else{//is not deletedlabeltext.hidden=YES; } }Else{//the length is not 1 timeslabeltext.hidden=YES; } } returnYES; }
IOS Controls-TextView implementation Placeholder Memo