insetForSectionAtIndex (on DelegateFlowLayout) enables one to set insets for all cells within a section
sectionInset (on FlowLayout) enables one to set insets that applies to all sections.
However, I am looking for a way of applying insets to only one specific section - is this possible?
Section insets are margins applied only to the items in the section. They represent the distance between the header view and the first line of items and between the last line of items and the footer view. They also indicate the spacing on either side of a single line of items.
A layout object that organizes items into a grid with optional header and footer views for each section.
In essence, UICollectionViewLayout is just a class object that takes the responsibility of arranging the child views of a UICollectionView. But in UICollectionView world, we call the child views Cell and we set the views through a wrapper class called UICollectionViewLayoutAttributes.
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;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With