nyanev
nyanev

Reputation: 11519

Dynamic expand UITextView

I have UITextView and I want to expand it dynamically. If the text is should scroll I want to expand the view to fit the amount of the text. How can I do that. Thanks

Upvotes: 3

Views: 5089

Answers (2)

tipycalFlow
tipycalFlow

Reputation: 7644

You will have to find the heightof the text you need to contain inside the UITextView (of a particular fixed width) and then set its frame height to that value so that it is not scrollable. You can go through this example to see how exactly to do that.

Upvotes: 1

mayuur
mayuur

Reputation: 4746

When you end the editing of your text write this.

- (void) textViewDidEndEditing:(UITextView *)textView
{
    CGRect frame = myTextView.frame;
    frame.size.height = myTextView.contentSize.height;
    myTextView.frame = frame;
}

Upvotes: 15

Related Questions