IOS Uitextview Plus placeholder

Source: Internet
Author: User
Tags vars

Uitextview on how to add a similar to the Uitextfield placeholder, in fact, add a uilabel on Uitextview, and then realize

-(BOOL) TextView: (uitextview *) TextView shouldchangetextinrange: (nsrange) range Replacementtext: (nsstring *) Text This proxy method is possible.

The specific implementation is as follows:

[OBJC]View Plaincopy< param name= "allowfullscreen" value= "false" >
  1. -(BOOL) TextView: ( Uitextview *) TextView shouldchangetextinrange:(nsrange) range replacementtext:( NSString *) Text
  2. {
  3. if  (![ Text isequaltostring:@ ""]) {
  4. _label1. Hidden = YES;
  5. }
  6. if ([Text isequaltostring:@ "] && range. location = = 0 && range. length = = 1) {
  7. _label1. Hidden = NO;
  8. }
  9. return   YES;
  10. }

The description is as follows:

(1) _label1 is added to the Uitextview on the Uilabel

(2) [Text isequaltostring:@ ""] means the BACKSPACE key is entered

(3) Range.location = = 0 && Range.length = = 1 indicates the first character entered

The effect is as follows:

the original http://blog.csdn.net/chchong1234/article/details/24646719 thanks to bloggers for sharing ~

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.