曾祥林 曾祥林 - 1 month ago 44
iOS Question

How to caculate UITableViewCell Height when have more UILabel?

We use systemLayoutSizeFitting to caculate UITableViewCell`s height when number of UILabel less than 2, like this:
single image

How to caculate Cell Height when have more UILabel like this?
enter image description here

tim tim
Answer

from your 2nd image it looks like you haven't set constraints correctly for vertical direction (red color).

can i ask why you need height?

if it's for heightForRowAtIndexPath: i'd suggest to use selfsizing cells? then you don't need to calculate height explicitly.

 self.tableView.estimatedRowHeight = 100.0;
 self.tableView.rowHeight = UITableViewAutomaticDimension;

 //remove delegate call
 func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {} 
Comments