I have a collectionView and the direction is set to Horizontal and every cell just contain a UIlabel and it's using autolayout to determine the width of the cell.
for example, there are three cells and it's default behaviour.
|[x] [xxx] [xxxxxxxxx] |
but the requirement is to center align these three cells if the total width of all cells doesn't exceed the width of the screen.
the left inset for the first cell should be
leftInset = (screen width - (first cell width + second cell width + third cell width + total spaces between the three cells) /) 2
the result would be
| [x] [xxx] [xxxxxxxxx] |
I have found a great answer for the cells with fixed width from How to center horizontally UICollectionView Cells?, but doesn't work on self-size one.
would be much appreciated if you would help.