Reputation: 3026
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
}
Upvotes: 2
Views: 784
Reputation: 3235
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
Upvotes: 4