Programmatically create UICollectionView with custom headers

后端 未结 4 1232
予麋鹿
予麋鹿 2020-12-29 22:39

I\'m making an iOS app in swift, and I\'m trying to make a collectionView programmatically. I want to use my own subclass of UICollectionReusableView as a header for the Col

4条回答
  •  萌比男神i
    2020-12-29 23:03

    you can do it like this:

    // Setup Header
    self.collectionView?.registerClass(CollectionCustomHeader.self, forSupplementaryViewOfKind: CustomeHeaderHeader, withReuseIdentifier: "customHeader")
    

    also:

    override func collectionView(collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, atIndexPath indexPath: NSIndexPath) -> UICollectionReusableView {
    
    if kind == CustomeHeaderHeader {
        let view = collectionView.dequeueReusableSupplementaryViewOfKind(kind, withReuseIdentifier: "parallaxHeader", forIndexPath: indexPath)
        return view
    }
    

提交回复
热议问题