UICollectionview的自定义页脚视图在swift中

我正在快速写一个客观的C应用程序的min,并决定集合视图效果更好,然后在我的情况下tableview。 所以我有collectionview所有设置正是我想要的,现在我需要添加一个页脚到我的collections视图。

在Objective-C中,对我来说非常简单,我所做的只是创build一个UIView,添加对象,并将其添加到我的tableview中。

self.videoTable.tableFooterView = footerView; 

现在我一直试图在我的collections视图中得到类似的解决scheme,但是到目前为止我还没有运气。

有一个简单的.collectionviewFooterView或我可以添加我的UIView?

编辑我发现这里有类似的想法,如果这有助于创build一个答案

编辑

我一直在想方法来实现这一点,所以现在我的想法是使用下面的代码将页脚视图添加到集合视图的末尾:

 var collectionHeight = self.collectionView.collectionViewLayout.collectionViewContentSize().height footerView.frame = CGRectMake(0, collectionHeight, screenSize.width, 76) 

唯一的问题,我有这个解决方法是我需要添加更多的空间到colletionView的contentView,我没有运气

我的解决scheme

我解决了它使用解决方法(不漂亮,但它的工作原理),我添加UIView到uicollectionview使用一个简单的

 footerView.frame = CGRectMake(0, collectionHeight - 50, screenSize.width, 50) self.collectionView.addSubview(footerView) 

并使用此设置布局插图:

 alLayout.contentInsets = UIEdgeInsetsMake(2, 2, 52, 2) 

集合视图处理页眉和页脚与表视图不同。 你需要:

  1. 注册您的页脚视图类使用:

     registerClass(myFooterViewClass, forSupplementaryViewOfKind: UICollectionElementKindSectionFooter, withReuseIdentifier: "myFooterView") 
  2. 在您的集合视图布局上设置headerReferenceSize ,或者在您的delegate实现collectionView:layout:referenceSizeForHeaderInSection: delegate

  3. 在你的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 } 

我认为这就是一切!