I'm working on autolayout for UITableViewCell
with a multiline UILabel
. My UILabel
is anchored to top, right, bottom and left. Everything is working fine, until I add some top margin; if I do, some cell heights are calculated fine, and some don't, so the text gets truncated on those cases.
I've simplified my view as is a bit more complex. It looks like this:
This is the relevant code where I calculate the cell's height:
CellMessage *cell = self.prototypeCell;
cell.message = [self messageForRowAtIndexPath:indexPath];
[self.prototypeCell layoutIfNeeded];
CGSize size = [self.prototypeCell.contentView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize];
message.cellHeight = size.height + 1;
I have read lots of sof threads and tutorials, and all of them differ on subtle points, sometimes they said setting a preferred max width is the key point, I tried setting and not setting it, but I'm having the same results, still I don't completely understand how this param works :(
What am I missing / doing wrong? Anything I could try, or any tip pointing in the right direction would be much appreciated.