UICollectionView-如何设置行的背景色 [英] UICollectionView - How to set background color of a row
问题描述
我有一个 UICollectionView
和只有一个部分.有没有一种方法可以设置每行的背景颜色?(在我的情况下,它将是从黑色到白色的渐变)
I have a UICollectionView
and only one section. Is there a way to set the background color of every row? (in my case it would be a gradient from black to white)
推荐答案
CollectionViews实际上没有行的概念,因为它被设计为具有灵活的布局.
CollectionViews don't really have a concept of a rows because it's designed to have a flexible layout.
您最好的选择可能是使单元格的背景具有您的图案,并删除单元格之间的所有填充/边距.
Your best option is likely to have the background of the cells have your pattern and remove all the padding/margin between the cells.
如果最后一行未满,这将是一个问题,因此,如果数字需要灵活,则必须添加空单元格.
This will be a problem if the last row isn't full, so if the number needs to be flexible you would have to add empty cells.
这篇关于UICollectionView-如何设置行的背景色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!