I'm really struggling here. I remember UITableView.tableHeaderView as a source of problems when I first entered the iOS development in 2014. 5 years later, here we are – nothing has changed.
Basically, I want something like this, except that I just want a label in each cell, and I want the label + strip below it to determine the size of the cell. Unfortunately, the code used to make it not so useful because a) it uses automatic resizing masks for some parts of the control, and b) it requires you to specify the control height explicitly.
A UIControl subclass is the peak level display used as a table header display
a UICollectionView is inside the control, with all edges attached to its
each cell has all edges of the label / strip attached to
contentViewexcept the bottom of the label and the top of the strip attached to each other
I have done what I thought were all necessary steps for this to work:  Return
requiresConstintBasedLayout in all subclasses (control and cell)
layout.itemSize = UICollectionViewFlowLayoutAutomaticSize
layout.estimatedItemSize = CGSizeMake (nonzero, nonzero);
translatesAutoresizingMaskIntoConstraints for all views involved, except cells
contentView ] s and the table view of course
updateConstraints in the control to pinch the collection view to itself on all pages
updateConstraints in the cell class to pin on all subviews
Set the table view top view to the control in
I tried even things I did not know I needed to do / things that are not clear are needed in the documents:
topanchor to it in its monitoring
Manually insert the
frame of the controller. format
] systemLayoutSizeFittingSize: UILayoutFittingCompressedSizeon the control, and then set it as header view again
preferredLayoutAttributesFittingAttributes:in the cell class  Here are links to relevant files / lines. The repo is here on the branch
To test it, start the UICatalog app and tap the globe icon in the FLEX window. The background to the control is set to
redColorso it should be very clear when the control is actually displayed.
Any help is appreciated 🙂 Thanks in advance