Custom Uitextview placeholder (placeholder text)

Source: Internet
Author: User

We know that in iOS development, the control Uitextfield has a placeholder property, Uitextfield and Uitextview use the method basically similar, there are two small differences: 1. Uitextfield single-line input, while Uitextview can enter multiple lines. 2.UITextField has a placeholder attribute, and Uitextview does not. As for the two agent method, the principle is basically similar, but the method name slightly different.

How to add a placeholder function for Uitextview, in fact, the method is very simple, three steps can be achieved:

1. When creating a TextView, assign its Text property

namely Textview.text = @ "Want to say words";

2. In the agent method to begin editing, do the following

-(void) textviewdidbeginediting: (Uitextview *) TextView {

if ([Textview.text isequaltostring:@ "want to say"]) {

Textview.text = @ "";

}

}

3. In the proxy method that ends the edit, do the following

-(void) textviewdidendediting: (Uitextview *) TextView {

if (textview.text.length<1) {

Textview.text = @ "words to say";

}

}

After the simple three steps above, you can realize the placeholder function, of course, you may also customize a uitextview, beautify, such as adding placeholder text color and so on attributes.

Custom Uitextview placeholder (placeholder text)

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.