简体   繁体   English

如何为每个单元格设置自定义“收集视图”单元格间距

[英]How to set custom Collection View Cell spacing for every cell

I have a Collection View and I want to calculate the spacing between every single cell programmatically but I can't find out how to do this. 我有一个“集合视图”,我想以编程方式计算每个单个单元格之间的间距,但是我不知道如何做到这一点。

So, how can I calculate the inter-cells spacing between UICollectionViewCells in a UICollectionView with UICollectionViewFlowLayout? 那么,如何在使用UICollectionViewFlowLayout的UICollectionView中计算UICollectionViewCells之间的小区间间距?

Below is how you set custom cell spacing in a collectionview. 以下是如何在collectionview中设置自定义单元格间距。 You have to create an extension. 您必须创建一个扩展。

extension ViewController : UICollectionViewDelegateFlowLayout {

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {

    return //whatever you want//

}

Make sure the "ViewController" that follows extension is the name of your viewcontroller. 确保扩展名后面的“ ViewController”是您的ViewController的名称。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM