How do I change the horizontal spacing between cells in a horizontal scroll collection view

戏子无情 提交于 2020-06-01 07:37:06

问题


I have a collection view which is basically a horizontal table view. It's one line of cells that scrolls left and right. Sort of like a carousel without the fancy animation. I would like to be able to control the distance between cells. There is a property for doing that in the interface builde. It is in the collection view flow layout, in the inspector (in the tab with the little ruler where you usually see constraints). It is called Min. Spacing and has two variants: For Cells and For Lines. I changed the value of For Cells but it doesn't affect the spacing. Neither does changing the parameter minimumInteritemSpacing or using the collection view callback for specifying that parameter on a per section basis. Help!


回答1:


The answer is that in a horizontal scroll collection view, the distance between cells, even the horizontal distance, seems to be controlled by the For Lines parameter (in IB) or minimumLineSpacing parameter of the CollectionViewFlowLayout.

This answer is also buried in some answers I saw more general question about cell spacing in collection views: https://stackoverflow.com/a/48791318/826946 and https://stackoverflow.com/a/37420529/826946

I decided to separate it out into a separate question that directly addresses the issue of horitzontal scroll collection views.



来源:https://stackoverflow.com/questions/61774415/how-do-i-change-the-horizontal-spacing-between-cells-in-a-horizontal-scroll-coll

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!