首页 > 解决方案 > 删除特定 UICollectionViewCells 之间的间距

问题描述

我正在使用在collectionItems之间UICollectionFlowLayout建立minimumLineSpacing,我试图找到一种方法将某些单元格的间距设置为零,因此没有间距,即它们似乎被“合并”而其他人的空间完好无损,是否有可能cellForItemAt例如在方法中进行更改以实现此目的?

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
     let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "customColCell", for: indexPath) as! customColCell

     if indexPath.row == 5 {
        self.minimumLineSpacing = 100 // -- this does not result in an individual change...
     }

     cell.textLabel.text = indexPath.row.description
     return cell
}

标签: swiftuicollectionviewuicollectionviewcell

解决方案


是否可以在 cellForItemAt 方法中进行更改以实现此目的

不,您要求做的不是 UICollectionViewFlowLayout 默认的行为方式。您将需要编写一个集合视图布局子类。


推荐阅读