0

我创建的CollectionView如下:安装头单元格UICollectionView

enter image description here

我想创建集合视图与此相同的布局,如一个用红色iPhone7一个最大头单元格。现在我想知道哪种方法更好,创建一个额外的单元格或在UICollectionViewFlowLayout中处理?我的数据是从JSON中提取的数组,因此我想让大单元格成为第一项。

老实说,我看到第二种方法非常复杂。

所以任何人都可以帮助我找到最佳解决方案。 非常感谢您阅读本文,并祝您有愉快的一天。

+0

创建集合视图两个部分,为第一个与大宽度 –

+0

你需要锚头滚动时顶部? –

+0

我的数据是从JSON中提取的数组,所以我想让大单元是第一项。 –

回答

0
  1. 转到属性检查员UIColectionView

  2. 从配件选择章节标题

  3. 一旦头视图中可见,请将您的意见吧。

然后在下面的方法调整相应:

override func collectionView(_ collectionView: UICollectionView ,viewForSupplementaryElementOfKind kind: String,at indexPath: IndexPath) -> UICollectionReusableView { 
     if kind == UICollectionElementKindSectionHeader{ 
     return headerView 
     } 
    } 
+0

请检查以下内容:https://stackoverflow.com/questions/43365238/add-a-view-to-collectionview-header-in-storyboard/43365352#43365352 – ankit