My application uses an UITextView
. Now I want the UITextView
to have a placeholder similar to the one you can set for an UITextField
.<
Here's yet another way to do it, one that reproduces the slight indentation of UITextField
's placeholder:
Drag a UITextField
right under the UITextView
so that their top left corners are aligned. Add your placeholder text to the text field.
In viewDidLoad, add:
[tView setDelegate:self];
tView.contentInset = UIEdgeInsetsMake(-8,-8,0,0);
tView.backgroundColor = [UIColor clearColor];
Then add:
- (void)textViewDidChange:(UITextView *)textView {
if (textView.text.length == 0) {
textView.backgroundColor = [UIColor clearColor];
} else {
textView.backgroundColor = [UIColor whiteColor];
}
}