This is a sample of a Centered CollectionView Flow Layout, that is in detail explaing in my blog post here.
The result of the layout looks like:
Just initialize the UICollectionViewCenterLayout object and set it as the collectionViewLayout of your UICollectionView:
let layout = UICollectionViewCenterLayout()
layout.estimatedItemSize = CGSize(width: 140, height: 40)
collectionView.collectionViewLayout = layout