1
votes

I'm working on UICollectionView inside UITableViewCell. Using "UICollectionReusableView" as header view. The width of header view is 100. Before I introduce header view the CollectionViewCell started at the beginning of CollectionView, which is as expected. After I put header view, CollectionViewCell starts at end of header view width. I think somewhere position is not set properly.

CollectionView Scroll direction is Horizontal. I have used UICollectionViewFlowLayout to present the CollectionViewCell.

    let layout =  UICollectionViewFlowLayout()
    layout.sectionInset = UIEdgeInsets(top: 5.0, left: 5.0, bottom: 5.0, right: 5.0)
    layout.minimumInteritemSpacing = 8.0
    layout.minimumLineSpacing = 5.0
    layout.scrollDirection = .horizontal
    layout.sectionHeadersPinToVisibleBounds = true
    collectionView.collectionViewLayout = layout

I have set the size of the header view using "referenceSizeForHeaderInSection" delegate. enter image description here Any hints where I might be wrong.

1
If I understand your question correctly, it would "start at end of header view width", since the scroll direction is horizontal.. - AjinkyaSharma
@AjinkyaSharma, Yes, you are right. If I comment out the scroll direction then CollectionViewCell starts at center and the scroll direction goes vertical. - selva

1 Answers

1
votes

Instead of using UICollectionViewFlowLayout, you should subclass this and override the method layoutAttributesForSupplementaryViewOfKind: And give your frame accordingly