I have following, completely ruined design after I tried to implement dynamic-vertical UIStackView inside UITableViewCell:
As you noticed, the label on top of this card is not fitting inside cell. Basically, this cell contains following UI components:
- The UILabel (that one which is not fitting). Constraints: top, leading, trailing.
- UIStackView(distribution&alignment fill) (it shows list of items with price). My custom view which is responsible for showing item's name and price is inserted to this stackview. Constraints: top to bottom of UILabel (that one which is not fitting), leading, trailing.
- The UIView (that divider line with constant height). Constraints: height constraint, leading, trailing, top to bottom of UIStackView.
- The two UILabel's (Full amount and total price. You can see it on image). Constraints: Top to bottom of divider line, leading, trailing and bottom constraints.
I set most intuitive constraints in XIB file. There are no errors or warnings. But anyway, the cell is not showing full content inside of it. I have following guesses:
- This cell is not alone. I also show other custom cells that have different intrinsic heights. I think iOS doesn't understand how to calculate the height of this cell. Then, I implemented methods estimatedHeightForRowAt and heightForRowAt by returning UITableView.automaticDimension. But, anyway, it didn't help.
- I think it is because of hugging or compression resistance priorities. That label is not fitting because it has equal compression resistance as other views. So, Auto Layout randomly decides which view should be ruined and just ruins that view. Ok, I set maximum compression resistance to that label and know it is fully shown. But, Auto Layout decides to destroy my UIStackView by clipping texts inside of it, even they have numberOfLines set to 0. I don't want my views to be clipped. I want them to be shown fully.
It seems serious problem. So, how can I solve it. Here is how constraints are set: