Search code examples
iosswiftautolayout

AutoLayout : Needs constraints for Y position or height (trying to use views with content with dynamic heights)


I want to create a UITableViewCell with many UIViews, vertically stacked. Some of those UIViews are more complex, with many subviews inside for example.

I tried to create one for example. The first subview is a header view with a label horizontally centered with an unknown number of lines, and the other contains an image view on the left and a view with a label inside on its right (like a cell in a messager view). Straight from IB :

enter image description here

The header view and the descending constraints for the header label:

enter image description here

The bottom view:

enter image description here

The avatar image view:

enter image description here

The subview with the message label constraints inside:

enter image description here

However some things are still missing:

enter image description here enter image description here

What am I missing here? Thanks for your help.


Solution

  • You want vertically stacked views, so you should use StackView and set the axis property to vertical.

    If all views have the same size, then set your distribution to fill equally, otherwise fill proportionally.

    https://www.raywenderlich.com/508-uistackview-tutorial-introducing-stack-views