Adding Placeholder Text to UITextView
I decided one of my apps should display placeholder text in a text view. Unfortunately UITextView does not have a placeholder property. I’ve always thought this is odd especially given the fact that UITextField has a placeholder property.
I googled to see what others have done. I found some good approaches but no one solution that I liked. So I decided to write my own borrowing from the various ideas of others. The end result is KTTextView.
KTTextView derives from UITextView and enhances it with new features. At the moment the only new feature is the placeholder text. The placeholderText property works same as UITextField’s placeholder property. I also added the property placeholderColor in case an app has the need to use a color different then the default placeholder color.
KTTextView is hosted on github. The project includes a sample app showing how to use KTTextView. I plan to add more features as time allows. One feature I want to add is an option to display the text view in a rounded rectangle giving it a similar look to UITextField. In the meantime, I hope you find the KTTextView’s current implementation useful.



December 11th, 2010 at 6:45 pm
Is there a way to reload the placeholder after the view in which the modified textView is on disappears? The nib I have the KTTextView on is used multiple times. After it is used the first time the placeholder no longer appears. Does the awakeFromNib method only run the first time the nib is loaded?
December 11th, 2010 at 7:27 pm
Not sure I understand what it is you are trying to accomplish. awakeFromNib is called when the nib is unarchived. You should not set the placeholderText in this method. Instead, set the placeholderText in viewDidLoad or in viewWillAppear:.
-KIRBY