Add button at end of collection view in storyboard

I have UICollectionViewController

a storyboard. I know how to add cells and modify them, but for some reason I cannot add any other view or UI element after mine UICollectionView

.

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

+3


source to share


2 answers


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

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



You may also need to set the reference size of the footer if you UICollectionViewFlowLayout

+5


source


Swift 2.1 Solution:

In the storyboard, select Collection View > Attributes Inspector > Enabled Section Footer

Once this is enabled, the section view will appear and you can drag your views onto it.

Select the header view, and set the Identifier

... ex:FooterViewID



Next, in your 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 should now appear at the bottom of the interface.

+1


source







All Articles