0

Im embedding a text view inside a table view cell. This text view is meant for writing long text.

How do it get a variable height uitextview that expands automatically when the entered text exceeds the assigned height of the uitextview. It must work like composing a message in the Mail app.

Anand
  • 10,310
  • 24
  • 90
  • 135
  • Check this [link](http://stackoverflow.com/questions/4015557/uitextview-in-a-uitableviewcell-smooth-auto-resize-shows-and-hides-keyboard-on-i). Hope it helps! – Amar May 31 '12 at 06:43

3 Answers3

0
  1. Set and implement delegate of UITextView delegate protocol
  2. Check size of UITextView.contentSize. If it's height parameter has changed then you should expand table view cell: 2.1 Reload particular cell. 2.2 Return new height value in UITableViewDelegate method.
Nekto
  • 17,837
  • 1
  • 55
  • 65
0

Take a look at this SO question.

You can take the font property from UITextView to use in the sizeWithFont: method.

You should implement the UITextViewDelegate protocol and every time the text view changes, that is, when – textViewDidChange: gets called you should reload the cell to adjust it to the content's size.

To reload a specific row, you can use – reloadRowsAtIndexPaths:withRowAnimation:.

Community
  • 1
  • 1
Fran Sevillano
  • 8,103
  • 4
  • 31
  • 45
0

I managed this via Storyboard using the Content Hugging Priority property.

In IB I set the Text View height to a default value and gave this a priority of 250 (Low).

Text View Height1

I then set the Content Hugging Priority to 1000. The view resized to fit the text exactly I wanted. Content Hugging Priority2

Hope this helps