How to change space between cells in UICollectionView?
//Objective c- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath { return CGSizeMake((collectionView.frame.size.width/3)-20, 100); }// Swift 2.0func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize { return CGSizeMake((collectionView.frame.size.width / 3) - 20, 100)}// Swift 3.0override func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize { return CGSize(width: CGFloat((collectionView.frame.size.width / 3) - 20), height: CGFloat(100))}
On your code, you have to create a IBOutlet to your collection view, and then assign the collectionViewLayout as such:
let layout: UICollectionViewFlowLayout = UICollectionViewFlowLayout()layout.sectionInset = UIEdgeInsets(top: 20, left: 2, bottom: 10, right: 2)layout.minimumInteritemSpacing = 0layout.minimumLineSpacing = 0layout.scrollDirection = .horizontalcollectionView!.collectionViewLayout = layout