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

标签 ios uiview uicollectionview uicollectionreusableview

我希望使用 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/

相关文章:

objective-c - 将 NSManagedObject 保留在 CoreData NSManagedObjectContext block 之外

ios - 向 iOS 项目添加和访问二进制 blob 原始数据文件

iphone - UIView 应该如何获取对其子级的引用?

ios - UIView 在没有 UIViewController 的情况下获取宽度/高度

swift - 即使我为 UICollectionViewDataSource 添加了方法,它也会给我一个错误

ios - 单元格包含 UITableViews 的 UICollectionView

ios - XCUITest 预测试设置

ios - iPhone显示屏灯不会自动关闭

ios - UIScrollView contentInset 自动布局问题

ios - 更改 UICollectionView 中单元格的文本时应用程序崩溃