I have set setMaXPreferredLayoutWidth
to UILabel
and added all the required constraints to the UIlabel
now I can see multiline UIlabel
in my UItableviewcell
but my problem is I am getting extra padding at the top and bottom of my UIlabel
based on MaxpreferredLayoutWidth
value.
When I set the MaxPreferreLayoutWidth
to 200 I get this
When I set the MaxPreferreLayoutWidth
to 100 I get this
In general UIlabel
height depends based on preferredMaxLayoutWidth
.
Can any one say me how to remove this extra padding and render the exact height of UIlabel
?
We have to set the tableviewcell's frame while calculating the height of the cell in heightForRowAtIndexPath
Ex:
[tableViewCell setFrame:CGRectMake(0, 0, CGRectGetWidth(self.tableView.bounds), CGRectGetHeight(tableViewCell.bounds))];
and then in layoutSubviews
method of UItableviewcell
we have to set the preferredMaxLayoutwidth
Ex:
[self.multilineLabel setPreferredMaxLayoutWidth:CGRectGetWidth(self.bounds)];