【问题标题】:How to use a UIView Subclass as a UICollectionView footer如何使用 UIView 子类作为 UICollectionView 页脚
【发布时间】:2016-12-07 21:30:00
【问题描述】:

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

【问题讨论】:

    标签: ios uiview uicollectionview uicollectionreusableview


    【解决方案1】:

    如果您的 CustomUIView 不是 UICollectionReusableView 的子类,您将无法将其转换为 UICollectionReusableView

    你有几个选择:

    • 如果它满足您的需求,您可以为您的 CustomUIView 类继承 UICollectionReusableView,而不是继承 UIView

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

    【讨论】:

      猜你喜欢
      • 2014-02-26
      • 2013-07-26
      • 2013-01-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-03
      • 2022-11-08
      • 1970-01-01
      相关资源
      最近更新 更多