[英]How to center align CollectionView Cell?
您可以使用多个部分来解决此问题。 条数应为
numberOfSection = totalItemCount/3 > Int(totalItemCount/3) ? Int(totalItemCount/3) + 1 : Int(totalItemCount/3)
不要使用天花板。 然后该部分中的项目数应为
numberOfItemInSection = totalItemCount-section*3 < 3 ? totalItemCount-section*3 : 3
然后实现UICollectionViewDelegateFlowLayout
委托。 在collectionView(_ collectionView:, layout:, insetForSectionAt:)
设置的位置,
let minimumInterItemSpacing: CGFloat = 8.0
// minimumInterItemSpacing should be same in the delegate function
let itemCountInSection = collectionView.numberOfItems(inSection: section)
let edgeSpace = (collectionView.bounds.width - ((itemCountInSection*self.itemWidth) + (minimumInterItemSpacing*(itemCountInSection-1)))) / 2
return UIEdgeInsets(top: self.topSpace, left: edgeSpace, bottom: self.bottomSpace, right: edgeSpace)
设置其他适合您的委托方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.