Reputation: 3898
We have two(first label dynamic height) labels and one in UITableview and our image size static assume that 120*70
We are setting image bottom constraint to cell superview but when Label content height is more than image height, second label going inside cell automatically.
We are using UITableViewAutomaticDimension
Here we confused to set constraint to labels, How to proportionally set heights to both labels and image.
If we try to bottom constraint to label and fixed height to and width to image, then white space coming at bottom of cell.
My cell design looks like below image:
Check my output with below constraints
Output:
Constraint image:
Upvotes: 1
Views: 1450
Reputation: 77486
You can do this easily by setting a bottom constraints of greater-than-or-equal to both the bottom label and the image view.
First, make sure you are using:
tableView.rowHeight = UITableViewAutomaticDimension
tableView.estimatedRowHeight = 100
so the cells / rows will auto-size to fit the contents.
For the cell prototype, I have (background colors so we can see the frames):
8
and Leading 8
(from the superview, not using margins)8
and Trailing 0
(from the superview, not using margins), and Width 119
Height 87
(based on your posted image)4
to Multi-Line label8
to the image viewNow the key is the next two constraints...
>= 8
to Bottom of superview>= 8
to Bottom of superviewNow, the cell height will auto-expand to fit the taller elements:
and, how it looks without the colored backgrounds:
The full project can be found here: https://github.com/DonMag/AnotherExpandingCell
Upvotes: 6