iOS - How do I create a UITextView with placeholder text?
Solution 1
There are many ways to do this.
Approach #1: UITextView does not have a property for placeholder so you'd have to set the text property to the instructions you would like to have and then as soon as the user taps the UITextView clear it out.
Approach #2 There is a subclass of UITextView that someone made that adds a Placeholder property
Solution 2
Maybe you are looking for a UITextField.
UITextFields are the more appropriate thing for this method. Then you may use the "placeholder" property to change the greyed-out text.
Duck
Updated on October 26, 2020Comments
-
Duck over 3 years
Possible Duplicate:
Placeholder in UITextViewI am relatively new to iOS and I don't know how to call this in english, but I want to create some
UITextViews
that contain instructions or pre filled text, like "type your name here", or "type your phone", etc, written in light color text but when the user selected the text view to start typing the hints they contain vanish.Is there any example/tutorial etc. I can follow to learn more about it?
How do I do that in iOS?
-
cbowns almost 11 yearsI've written an updated version of the UITextView subclass to cover dictation and a couple other text entry methods that
GCPlaceholderTextView
missed. It's on Github. -
William LeGate over 10 yearsThe subclass works great. Implemented in 30 seconds