What's the best way to create a placeholder for a UITextView and the placeholder will have different colors and fonts. An example of what I want is:
_textView = [[UITextView alloc] initWithFrame:CGRectMake(7.0, 35.0, 306.0, 90.0)];
_textView.text = @"This is a variable called foo.";
I want "foo" in the text to be bolder and darker in color.
How's this best done?
I have Simple way for this .
Add UILabel
in UITextView
below and set UITextView
clearColor .and set your UILabel
text as you required and set that text color same as your requirement color . and if you click on textview then hide that label and if you clear all textview then show your placeholder label.
See this Example
- (void)textViewDidEndEditing:(UITextView *)theTextView
{
if (![textView hasText])
{
lbl.hidden = NO;
}
}
- (void) textViewDidChange:(UITextView *)textView
{
if(![textView hasText])
{
lbl.hidden = NO;
}
else
{
lbl.hidden = YES;
}
}
I hope this idea is useful for you.