Reputation: 4244
I have a UITableViewCell
, and i am using UITableViewAutomaticDimension
to automatically calculate the row height.
(I am replicating design of Facebook comments from iOS)
I need all the 4 label's height adjusted to height of their content.
CC = Content compression CH = Content hugging [Horizontal/Vertical]
Label 1: CC = 750/750 CH = 249/750
Label 2: CC = 999/999 CH = 999/999
Label 3: CC = 750/749 CH = 249/749
Label 4: CC = 1000/1000 CH = 1000/1000
Here, Label 2 and Label 4 are the most important labels. I dont want them to shrink anyhow. Label 1 and Label 3 can shrink but to a limit.(let's say 30px)
Let me know if anyone need more info.
Upvotes: 0
Views: 111
Reputation: 1241
I've tried to replicate your table view cell structure and it seems the issue is that preferredMaxLayoutWidth
of labels is not set.
You can either set it explicitly in Interface Builder or override table view cell's updateViewConstraints
method:
-(void)updateViewConstraints {
CGFloat gap = 40.0; // sum of leading and trailing space
[super updateViewConstraints];
label.preferredMaxLayoutWidth = self.view.bounds.size.width - gap;
}
Upvotes: 1
Reputation: 7582
You set layout constraint width
and Lines = 0
for both Label2 & Label4. See image below:
Label1
set top constraint
with superview
, otherwise set Vertical Spacing
with above label. Below is the result with large and short content for Label3
.
Edit: Your custom cell like here:
And you should update layout depending element view container.
Upvotes: 0