我正在快速重写 min 的 objective-C 应用程序,并决定在我的案例中 Collection View 比 TableView 更好。所以我已经完全按照我想要的方式设置了 Collection View ,现在我需要在我的 Collection View 中添加一个页脚。
在 objective-C 中,这对我来说非常容易,我所做的就是创建一个 UIView,向其中添加对象,然后像这样将其添加到我的 tableview。
self.videoTable.tableFooterView = footerView;
现在我一直在我的 Collection View 中尝试获得类似的解决方案,但是到目前为止我没有运气。
是否有一个简单的 .collectionviewFooterView
或我可以添加我的 UIView 的东西?
编辑 我发现了类似的想法 HERE如果这有助于创建答案
编辑
我一直在考虑如何实现这一点,所以现在我的想法是使用以下代码将页脚 View 添加到 Collection View 的末尾:
var collectionHeight = self.collectionView.collectionViewLayout.collectionViewContentSize().height
footerView.frame = CGRectMake(0, collectionHeight, screenSize.width, 76)
我在使用此解决方法时遇到的唯一问题是我需要为 colletionView 的 contentView 添加更多空间,但我对此并不走运
我的解决方案
我使用变通方法解决了它(不是最漂亮但它有效),我使用一个简单的方法将 UIView 添加到 uicollectionview
footerView.frame = CGRectMake(0, collectionHeight - 50, screenSize.width, 50)
self.collectionView.addSubview(footerView)
并使用此设置布局插图:
alLayout.contentInsets = UIEdgeInsetsMake(2, 2, 52, 2)
最佳答案
Collection View 处理页眉和页脚的方式与 TableView 不同。你需要:
使用以下方式注册您的页脚 View 类:
registerClass(myFooterViewClass, forSupplementaryViewOfKind: UICollectionElementKindSectionFooter, withReuseIdentifier: "myFooterView")
要么设置
headerReferenceSize
在您的收藏 View 布局或实现collectionView:layout:referenceSizeForHeaderInSection:
在你的delegate
.通过您的
dataSource
中的以下方法返回页脚 View :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 }
我想这就是一切!
关于ios - swift 中 UICollectionview 的自定义页脚 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26892247/