In this post, we will see how to resolve UICollectionView: remove separators for specific cells only
Question:I need to show separators for every cell in
UICollectionViewexcept every first cell of a section. I’m using list layout. So far I have only been able to remove all separators using
configuration.showsSeparators = false.
UICollectionLayoutListConfigurationhas a handler closure which allows you to configure the separator appearance on an item-by-item basis:
If you don’t want bottom separators for the first item in each section you can add a handler to your
UICollectionLayoutListConfigurationthat hides the separator for the first item:
truefor the grouped appearance so you don’t need to explicitly set that.
If you also want to remove the top separator you can easily do that too by adjusting
topSeparatorVisibilityin the handler in the same way.
If you have better answer, please add a comment about this, thank you!