Reputation: 1457
I have a custom UITableViewCell that has a UILabel with dynamic height, depending on it's content.
The resizing of the UILabel works perfectly, but the UILabel is not displaying It's content properly. The content is contained to 1 or 2 lines, even if it has space in It's frame.
BUT if I scroll the UITableView and the come back to those cells, everything is displayed perfectly.
I want the cells to be displayed correctly form the beginning without scrolling.
Here are some screenshots from before and after scrolling:
Here's the code I use for resizing the UILAbel:
CGSize expectedLabelSize = [titleText sizeWithFont:titleLabel.font
constrainedToSize:maximumLabelSize
lineBreakMode:titleLabel.lineBreakMode];
CGRect newFrame = titleLabel.frame;
newFrame.origin.y = 10;
newFrame.size.height = expectedLabelSize.height;
titleLabel.frame = newFrame;
accumulatedY += (expectedLabelSize.height + PADDING);
expectedLabelSize = [empresatext sizeWithFont:empresaLabel.font
constrainedToSize:maximumLabelSize
lineBreakMode:empresaLabel.lineBreakMode];
newFrame = empresaLabel.frame;
newFrame.size.height = expectedLabelSize.height;
newFrame.origin.y = accumulatedY;
empresaLabel.frame = newFrame;
accumulatedY += (expectedLabelSize.height + PADDING);
Upvotes: 0
Views: 616
Reputation: 1457
I "fixed" the problem by creating the UILabel programatically in "cellForRowAtIndexPath", as recommended in this thread: UILabel in a UITableViewCell With Dynamic Height
Still intrigued why this isn't working with the UILabel created in the InterfaceBuilder :/
Upvotes: 2