Custom Footer view for UICollectionview in swift

前端 未结 1 1880
太阳男子
太阳男子 2020-12-14 23:47

I am re-writting an objective-C app of min in swift and decided that a collection view works better then a tableview in my case. So i have the collectionview all set up exac

相关标签:
1条回答
  • 2020-12-15 00:05

    Collection views handle headers and footers differently than table views. You'll need to:

    1. Register your footer view class using:

      registerClass(myFooterViewClass, forSupplementaryViewOfKind: UICollectionElementKindSectionFooter, withReuseIdentifier: "myFooterView")
      
    2. Either set the headerReferenceSize on your collection view layout or implement collectionView:layout:referenceSizeForHeaderInSection: in your delegate.

    3. Return the footer view from the following method in your dataSource:

      func collectionView(collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, atIndexPath indexPath: NSIndexPath) -> UICollectionReusableView {
          let view = collectionView.dequeueReusableSupplementaryViewOfKind(UICollectionElementKindSectionFooter, withReuseIdentifier: "myFooterView", forIndexPath: indexPath)
          // configure footer view
          return view
      }
      

    I think that's everything!

    0 讨论(0)
提交回复
热议问题