3

Possible Duplicate:
Placeholder in UITextView

I 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?

Community
  • 1
  • 1
Duck
  • 34,902
  • 47
  • 248
  • 470

2 Answers2

16

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

shabbirv
  • 8,958
  • 4
  • 33
  • 34
  • 1
    I'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](https://github.com/cbowns/MPTextView/). – cbowns Jul 29 '13 at 21:42
  • The subclass works great. Implemented in 30 seconds – William LeGate Oct 09 '13 at 16:25
7

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.

Neil
  • 2,004
  • 3
  • 23
  • 48