I'm trying to add a text to UITextView to show while no editing and no content. Actually I'm trying to use it to show transparent UITextView. How can I add a pre-text to text view?
Asked
Active
Viewed 203 times
2 Answers
-1
This is quite the hack you can do:
set the default textView text to your 'pre-text' and the color is grayColor. using the below method:
Objective-C
- (void)textViewDidBeginEditing:(UITextView*) textView {
if ([textView textColor] == [UIColor grayColor]) {
[textView setText:@""];
}
[textView setTextColor:[UIColor blackColor]];
}
Swift
func textViewDidBeginEditing(textView: UITextView) {
if textView.textColor == UIColor.grayColor(){
textView.text = ""
textView.textColor = UIColor.blackColor()
}
}
you can then change the text and reset the text color to black color.

M.Alatrash
- 1,270
- 1
- 12
- 30