Dynamically shrinking textfield's frame to text inputted

211 views Asked by At

I have a textview that is created dynamically during an application's run time, with text inputted by user. How do I go about setting up the frame of the textview such that the frame is just about the size of the text? What I'm looking for is similar to how bubbles shrink and expand in, say, iMessages.

I'm using the following piece of code

CGRect frame = _textView.frame;
frame.size.height = _textView.contentSize.height;
_textView.frame = frame;

to adjust the height, but I'm not sure how to adjust both the height and width at the same time, given they both depend on user input.

1

There are 1 answers

1
npmrtsv On
[_textView sizeToFit];

Hope it helps.