0

Anyone ever implements something in UITextView that stopping it from receiving future inputs when the text length is smaller than certain threshold? I plan to implement a textview like we have in the mail composer interface. We have a placeholder "Subject" there, and the cursor starts after.

Placeholder in UITextView Inspired from this question, I wonder if there are some methods which could be used to stop changing the text in the UITextView once the cursor is moving back to the placeholder string.

Any ideas?

Community
  • 1
  • 1
Gill Bates
  • 21
  • 1
  • 3

2 Answers2

0

Well you could use something like..

- (void)textViewDidBeginEditing:(UITextView *)textView
{

    if (self.textView.textColor != [UIColor blackColor]) {

        self.textView.text = @"";
        self.textView.textColor = [UIColor blackColor];
    }

}

- (void)textViewDidEndEditing:(UITextView *)textView
{
//To display the placeholder text
    if (![self.textView.text length]) {

        self.textView.text = @"Description";
        self.textView.textColor = [UIColor lightGrayColor];
    }

}
Gokul
  • 1,236
  • 1
  • 14
  • 26
0

What about just clearing it, then pre-pending that text to whatever the user submits?

Robot Woods
  • 5,677
  • 2
  • 21
  • 30
  • right. This is what I am thinking currently. But by registering an observer for UITextViewTextDidChangeNotification event, we cannot easily intercept the letter which the user just typed. – Gill Bates Mar 19 '11 at 11:58
  • Very old post, but still worth saying: All i know is that using the `textView:shouldChangeTextInRange:replacementText:` delegate method can easily intercept the letter typed... Just use the replacementText to intercept what the user entered... – Cashew Oct 02 '12 at 22:08