在故事板中收集视图的末尾添加button

我有一个故事板中的UICollectionViewController 。 我知道如何添加单元格并修改它们,但由于某种原因,我无法在我的UICollectionView之后添加任何其他视图或UI元素。

在故事板中有没有办法做到这一点? 如果不是我怎样才能做到这一点编程?

在故事板中,您可以通过为您的UICollectionViewselect单选button标题“Section Footer”来启用它,然后在那里拖动UIButton。 你也可以重写这个函数:

- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath

如果您是UICollectionViewFlowLayout您可能还需要设置页脚的引用大小

Swift 2.1解决scheme:

在故事板中,select“ Collection View > Attributes Inspector > Enabled Section Footer

一旦启用,将出现一个截面视图,你可以拖动你的视图。

Select the header view, and set the Identifier 。 例如: FooterViewID

接下来,在您关联的视图控制器文件中,写入:

 func collectionView(collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, atIndexPath indexPath: NSIndexPath) -> UICollectionReusableView { let footerView = collectionView.dequeueReusableSupplementaryViewOfKind(kind, withReuseIdentifier: "FooterViewID", forIndexPath: indexPath) return footerView } 

页脚现在应该出现在您的界面底部。