如何使用 UIView 子类作为 UICollectionView 页脚



我希望使用UIView子类作为集合视图页脚(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

您有以下几种选择:

  • 如果它符合您的需求,您可以对自定义UIView类进行子类UICollectionReusableView,而不是子类化UIView

  • 由于UICollectionReusableView继承自UIView,因此您可以创建一个CustomUIView,然后创建一个新UICollectionReusableView并将您创建的CustomUIView添加为子视图

最新更新