Dynamically size uitableViewCell according to UILabel (With paragraph spacing)

前端 未结 4 1145
粉色の甜心
粉色の甜心 2020-11-29 13:24

I have a UITableView which is populated by text and images from a JSON file. The TableView Cell is currently sizing correctly for "posts" that do not contain many

4条回答
  •  借酒劲吻你
    2020-11-29 13:56

    The approach I recommend is to set the text of an actual label and get the required height by calling sizeToFit. For this to work, you've got to set the label's numberOfLines property to 0 and set the desired maximum width.

    When using this technique with table views, you can use the prototype cell method discussed here to calculate height using an actual cell.

提交回复
热议问题