Already read Auto-Layout: Get UIImageView height to calculate cell height correctly,the answer works well in ios 8 with UITableViewAutomaticDimension
, however it is not suitable for lower ios version.
I have created a dynamic height UITableView
with systemLayoutSizeFittingSize
.
There is a square UIImageView
in each cell, I want UIImageView
keep square in both iphone 5 and iphone 6/plus. So I set constraints to the imageview as :
The image view's height is set aspect ratio 1:1 to its width, and both the constraints on leading and trailing keep the imageview's width is equal to the cell. The bottom space from the imageview's bottom to the content view's bottom is 29 pixel.
Moreover, I wrote the code in the tableview delegate like
override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
let cell = tableView.dequeueReusableCellWithIdentifier("Cell") as UITableViewCell
return cell.contentView.systemLayoutSizeFittingSize(UILayoutFittingCompressedSize).height+1;
}
However, the result is not as same as what I predicate, the imageview is very long :
the red color is the background of the image view.
So what's going on?