0
votes

I'm using an UITableView to display cells that can contain a certain amount of text. This amount can vary depending on the dynamic cell. Because I have 2 UILabel, I'm not sure what is the best way to achieve the cell height calculation.

Here are the conditions:

  • UILabel *title = a label that can have from 1 to 4 lines
  • UILabel *subtitle = a label that can have from 0 to 2 lines (font is smaller than *title)
  • title + subtitle should be centered vertically (occurs when *subtitle have 0 line)

Do I have to create 2 dummies UILabel, fill them with cell contents, sizeToFit them adin finally get their height? Or is there an other, smarter, way to do that?

big thanks.

1

1 Answers

0
votes

With collection views you have to do as you suggest, and keep a static cell around to fill then resize after applying content to it.

If you use a dell with autolayout (constraints) you can get attractive cells with any content.

Also if your cell content is static while the user is using it, add a new property 'height' in the array managing content, so as to cache the size when you measure it the first time. That way you'll only need to determine the height once per entry.