0

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?

Encul
  • 93
  • 1
  • 10

2 Answers2

0

It is called a placeholder. It's part of the UITextField properties. placeholder

Lars Christoffersen
  • 1,719
  • 13
  • 24
-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