I have a UITableViewCell
with multiple UILabels
one of them is multi-line. All UILabels
has a fixed spacing with content hugging and compression resistance
as mentioned in the picture attached below.
In the code, tableView
and is a delegate
and dataSource
with rowHeight
property and heightForRowAt
set to UITableViewAutomaticDimension
I tried shuffling and making various arrangements with content hugging and compression resistance
values. But the height of the smaller cell with lesser text keeps the same size(as in the picture below) and the cell with more text appears just like it is supposed to be.
I haven't mentioned any height except estimatedRowHeight
i.e., 135
I made a height check with
print(cell.frame.height)
It return 140.0
for all cells.
Resultant looks like this:
label.setContentHuggingPriority(.required, for: .vertical)
or 1000. When you set it means that label wouldn't be stretched vertically beyond it's intrinsic heightcontentHuggingPriority
vertical to 1000 for allUILabels
and it's working as expected. Is that normal, I need to get my head around this. If you will post this as an answer, I will accept. Thank you.