4
votes

My Goal

I'm creating a custom UITableViewCell (MessageCell), and I'd wish to have my UITextView resizing both in width and height whenever the cell changes its size, while keeping some basic constraint like margins to the edges.

Note : I also change my cell's height in the heightForRowAtIndexPath method depending on the content which will be placed into UITextView.

What I tried

Here are all the constraints currently applied & the cell : enter image description here

I tried :

  • With a UILabel.
  • To fix a Vertical Space from the bottom, thinking it would change the height to fit all the constraints.
  • To override Height with an User Constraint Height >= 43 (my initial height), but the purple-automatic Height is re-created again whenever I do this.
  • To find a solution on SO first, but didn't find a case like (even if the UITextView's height's resize with autolayout seems to be a frequent issue).
  • Plenty of combinations of various & random constraints until my fingers bleds.

How it render now

enter image description here

So...

If someone has any clue or guideline to achieve my goal, I'd appreciate!

I might add, I'm totally new to Autolayout & constraints. My reference : Ray Wenderlich's awesomeness

1

1 Answers

3
votes

You need to get rid of that height constraint that the text view has. Make sure you have constraints to something above and below the text view (usually the top and bottom of the cell), and then you should be able to delete that height constraint.