Cells are not centralizing
Opened this issue · 4 comments
cs-joao-souza commented
My cells are not centralizing and have no ideia why.
Do i need to do something special?
dipkasyap commented
Same Here Cannot centralize LAST & FIRST , if i make my own design ! Please provide updated info on this issue if possible !
dubraf commented
I had the same problem when I was using :
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize
The solution was adding sectionInset for the layout inside above method :)
Ricardo1980 commented
Are you having this problem?
#32
armandsLa commented
Looks like this is being caused when section insets are not taken into account when sizing the cell. Subtracting them from item size fixes the issue.
func collectionView(_ collectionView: UICollectionView,
layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
let layout = collectionViewLayout as! UICollectionViewFlowLayout
var height = collectionView.frame.height
height -= layout.sectionInset.top + layout.sectionInset.bottom
return CGSize(width: height, height: height)
}