You must have to implement UICollectionViewDelegateFlowLayout
to your class with this method:
For Swift 4, 5+
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {
var edgeInsets = UIEdgeInsets()
if section == THE_SECTION_YOU_WANT {
// edgeInsets configuration stuff
}
return edgeInsets;
}
For Swift 3
func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAtIndex section: Int) -> UIEdgeInsets {
var edgeInsets = UIEdgeInsets()
if section == THE_SECTION_YOU_WANT {
// edgeInsets configuration stuff
}
return edgeInsets;
}