UICollectionReusableView method not being called

后端 未结 11 717
暗喜
暗喜 2021-01-31 13:13

I want my sections in the UICollectionView to have a header with an image.

I have followed these steps:

  • at the storyboard, assigned a header a
11条回答
  •  失恋的感觉
    2021-01-31 13:43

    It seems that you have to give your header a non-zero size or collectionView:viewForSupplementaryElementOfKind:atIndexPath isn't called. So either set the headerReferenceSize property of the flow layout like so:

    flowLayout.headerReferenceSize = CGSizeMake(self.collectionView.frame.size.width, 100.f);
    

    Swift 5+

    flowLayout.headerReferenceSize = CGSize(CGSize(width: self.collectionView.frame.size.width, height: 100))
    

    or, implement collectionView:layout:referenceSizeForHeaderInSection if you want to vary the size by section.

提交回复
热议问题