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)