0

I have a problem with a chat functionality that I'm trying to implement. Each row is a custom cell. The custom cell is initialized from xib file and has an UIView, and inside it there is a UITextview and a UIButton.

The problem: I always have the same width in my rows (cells) and I want them to adapt to the content. The height is ok (I use "heightForRowAtIndexPath"). I tried setting the frame in the cellForRowAtIndexPath with the following:

cell.message.frame = CGRectMake(cell.message.frame.origin.x, cell.message.frame.origin.y, MyNewRect.size.height, MyNewRect.size.height);

(By the way: cell.message is the UITextView)

I searched in other StackOverflow Questions but nothing really helped me. Maybe the problem is the container but I don't know how to resize both of them.

Edit: I add my XIB image and the constraints. enter image description here

enter image description here

Stanislav Pankevich
  • 11,044
  • 8
  • 69
  • 129
Okengroth
  • 83
  • 11
  • are you using Auto Layout? you should play with the constraints, you could calculate the size of the string, have a max width in order to go to new line – sken3r.MI Mar 29 '16 at 20:58
  • Yes, i've used AutoLayout in the xib. And thats actually happening. The problem is that if i send something short like "ok" the size of the container is the same (almost all the width) and i dont know how to adjust that width, not the height. – Okengroth Mar 29 '16 at 21:03
  • http://stackoverflow.com/questions/2669063/how-to-get-the-size-of-a-nsstring here is an example of how you could calculate the size of the text, you could use this to adjust your constraints – sken3r.MI Mar 29 '16 at 21:06
  • What do you mean by **the problem is the container**? And can you give a screenshot of the xib file with your constraints? – Yuchen Mar 29 '16 at 21:15
  • Yes, there is my xib and constraints – Okengroth Mar 29 '16 at 21:21
  • what is your iOS deployment target? – sken3r.MI Mar 30 '16 at 06:13

0 Answers0