2

I am looking to use a UIView subclass as a collection view footer (UICollectionReusableView). Since the class has already been written as a UIView

func collectionView(collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, atIndexPath indexPath: NSIndexPath) -> UICollectionReusableView {
    guard let footerView = self.collectionView.dequeueReusableSupplementaryViewOfKind(UICollectionElementKindSectionFooter, withReuseIdentifier:"CustomUIView", forIndexPath: indexPath) as? UICollectionReusableView else { break }
    return footerView
}
3254523
  • 3,016
  • 7
  • 29
  • 43

1 Answers1

4

You won't be able to cast your CustomUIView as a UICollectionReusableView if it doesn't subclass from UICollectionReusableView.

You have a couple of options:

  • If it works for your needs, you can subclass UICollectionReusableView for your CustomUIView class, rather than subclassing UIView

  • Since UICollectionReusableView inherits from UIView, you could create a CustomUIView, then create a new UICollectionReusableView and add the CustomUIView you created as a subview

JAB
  • 3,165
  • 16
  • 29