我希望使用 UIView 子类作为 Collection View 页脚 (UICollectionReusableView)。由于该类已被编写为 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
}
最佳答案
如果您的 CustomUIView 不是 UICollectionReusableView
的子类,则您将无法将其转换为 UICollectionReusableView
。
您有几个选择:
如果它满足您的需求,您可以为 CustomUIView 类创建
UICollectionReusableView
子类,而不是子类化UIView
由于
UICollectionReusableView
继承自UIView
,您可以创建一个CustomUIView
,然后创建一个新的UICollectionReusableView
> 并添加您创建的CustomUIView
作为 subview
关于ios - 如何使用 UIView 子类作为 UICollectionView 页脚,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41027723/