I'm trying to insert some multi-line label in a tableview cell, but it looks like in the image below. I would like the text wrapping at line break and occupying more lines as it needs, growing up the height of the cell if necessary.
In the image I would like that every label had the possibility to expand in multiple lines.
The label is embed in a vertical stackview that it's in turn embed in another stackview.
I've tried many many possibilities, including embedding every label in a view, setting 0 to label lines, and other things I found here on SO answers, but no, the labels are not wrapping correctly and they always occupy just one line.
EDIT:
I add a little explanation:
1) I think the problem is the stackview that it's setting automatically the height of the children views.
2) Yes, I can use dynamic height cells but that's not the point, cause for me it would be enough to have the cells all the same height, and when the text is not occupying two lines the cell will have more empty space under it. So my problem is just wrapping text of a label embed in a stackview
A view that presents data using rows in a single column. iOS 2.0+ iPadOS 2.0+ Mac Catalyst 13.1+ tvOS 9.0+
It sounds like what you are looking for is dynamic cell height, there are a few things that need to happen for that to work:
1) set label lines = 0
2) set the tableview's estimatedRowHeight in viewDidLoad
3) Either after setting the estimatedRowHeight in viewDidLoad set the rowHeight to UITableViewAutomaticDimension
or in heightForRow return UITableViewAutomaticDimension
4) Make sure that you do not have height constraints on the labels that you want to change height dynamically
Edited for updated question:
Since the label is in a stack view you want to make sure that the stack view does not have any height constraints and that it will adjust height as needed when the label expands.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With