[英]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.