In my UICollectionViewFlowLayout subclass I have this:
self.headerReferenceSize = CGSizeMake(280, 44);
However the header is displayed with a width of 320, which is the width of the collection view. This is correct according to the docs:
During layout, only the size that corresponds to the appropriate scrolling direction is used. For example, for the vertical scrolling direction, the layout object uses the height value returned by your method. (In that instance, the width of the header would be set to the width of the collection view.)
However, I need the width to be 280, and not stretch to the entire width of the collection view. How can I override this?
You don't need to add a subview to the header.
You want a header width of 280 in a Collection View of 320, so apply a Content Inset of 20 on the left and right, like so:
Swift
Xamarin
You can add another custom view over header and resize it as you wish. Ofcourse all you're components that were on header will go over custom view you created...