I ran into a problem with automatic cell sizes using auto-layout. My goal is to create a table that will look something like this:
| Title_label (time) $price | | | |Some long description. More | |description. | | |
When the title is long, it should look like this:
| This title is (time) $price | | really long | | | |Some long description. More | |description. | | |
Thus, when the title gets larger, it pushes the timestamp to the right, as long as there are 8 points in space, time and price. If it is even larger, it should be carried over to the next line.
I did in front of a table view with self-calibration cells, but where there is only one expandable label, not two.
I performed the automatic line height:
self.tableView.rowHeight = UITableViewAutomaticDimension self.tableView.estimatedRowHeight = 100
Here are my limitations:
| 8px |8px title 8px time >=8px price| | 8px | |8px description 8px| | 8px |
There is also an upper alignment between price time and name.
I set the number of title and description lines to 0. I set the time and price compression resistance to 1000 (because the title overlapped them).
However, the title label does not wrap to the next line. It ends up being ... Besides, it's too little. When I look at the table, the descriptive height is fixed.
I tried adding cell.layoutIfNeeded () before returning the cell. Then the cell layout is messed up (the header is cropped), but when I scroll through tV, everything is fine.
Any ideas?
Edit: Is this because the name label is next to other labels, and she does not know when it should fall?
I tried
override func layoutSubviews() { self.nameLabel.preferredMaxLayoutWidth -= (durationLabel.frame.width + priceLabel.frame.width + 16) super.layoutSubviews() }
to indicate the title label, what is its maximum width, but that will ruin everything.