首页 > 解决方案 > 如何快速使 Collectionview 单元格彼此靠近?

问题描述

我需要一个相邻的单元格,如下所示

在此处输入图像描述

但我是这样的:在短电话中,它们彼此相距甚远

在此处输入图像描述

对于collectionview,我给出了限制:

height = 80, leading = trailing = 0, top = 20

在 viewdidload 中:

  override func viewDidLoad() {
    super.viewDidLoad()
    //services collectionview cell
    let serviceLayout = UICollectionViewFlowLayout()
    serviceLayout.minimumInteritemSpacing = 0
    serviceLayout.minimumLineSpacing = 0
    serviceLayout.estimatedItemSize = UICollectionViewFlowLayout.automaticSize
    self.servicesCollectionView.collectionViewLayout = serviceLayout
    servicesCollectionView.contentInsetAdjustmentBehavior = .always
    servicesCollectionView.addObserver(self, forKeyPath: "contentSize", options: .new, context: nil)
   }

除了这个,我还没有给出任何东西..请帮忙..让collectionview单元彼此靠近

标签: swiftuicollectionviewcell

解决方案


推荐阅读