I'm loading up a table view where each table cell has some left indentation (think message threads/replies) and also contains a label which is of dynamic height (the contents of the reply). I'm using AutoLayout so the UILabel
sizes itself. In order to implement the indentation for each UITableViewCell
I followed the advice of people here on SO to override layoutSubviews
for my UITableViewCell
so it looks like this:
- (void)layoutSubviews
{
[super layoutSubviews];
float indentPoints = self.indentationLevel * self.indentationWidth;
self.contentView.frame = CGRectMake(indentPoints,
self.contentView.frame.origin.y,
self.contentView.frame.size.width - indentPoints,
self.contentView.frame.size.height);
}
What's happening now though is sometimes the UILabel text will be cut-off at the bottom. It seems to me that the UILabel is working off the old frame size when calculating it's appropriate height and drawing itself (since it is dynamic) not the new frame size which has indentation - with indentation, there is less width available for the same text, so it should know it needs to be taller.
If I remove this indentation and comment out my override of layoutSubviews
or if I put the call to [super layoutSubviews]
at the end, rather than the beginning, the text is no longer cut-off, but I lose my indentation.
What I want is for my UITableViewCell
to be indented appropriately and for my dynamic UILabel to recognise the new frame size and draw without any cut-off. I've tried putting in calls to layoutIfNeeded
in various places for my UILabel
without success.