Add button at the end of collection view in storyboard

空扰寡人 提交于 2019-11-27 03:40:12

问题


I have a UICollectionViewController in a storyboard. I know how to add cells and modify them but for some reason I can't add any other view or UI element after my UICollectionView.

Is there a way to do this in the storyboard? If not how can I do this programmatically?


回答1:


In storyboard you can enable it by selecting the radio button title "Section Footer", for your UICollectionView and then by dragging UIButton there. You can also override this function:

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

You may also need to set Footer's reference size if you are UICollectionViewFlowLayout




回答2:


Swift 2.1 Solution :

In Storyboard select Collection View > Attributes Inspector > Enabled Section Footer

Once that is enabled, a section view will appear, and you can drag your views to it.

Select the header view, and set the Identifier. ex :FooterViewID

Next, In you related view controller file,write :

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

The footer now should appear in your interface bottom.



来源:https://stackoverflow.com/questions/31577984/add-button-at-the-end-of-collection-view-in-storyboard

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!