How to change background color of a whole section in UICollectionView?

lichen19853 picture lichen19853 · Nov 28, 2012 · Viewed 16.2k times · Source

In UICollectionView, I want to give the whole section a uniform background color, instead of for a single cell or for the whole collection view.

I don't see any delegate method to do that, any suggestions?

Answer

FlySoFast picture FlySoFast · Oct 22, 2015

This is a great tutorial for changing UICollectionView section color:

Updated link, thanks to user @casamia

http://www.ericjchapman.com/jekyll/update/ios/2014/11/10/ios-changing-section-background-color-in-UICollectionView.html

Basically, we will have to subclass UICollectionViewLayoutAttributes, UICollectionReusableView and UICollectionViewLayout in order to create a instance UICollectionReusableView as section's background view.

This is his result:

enter image description here

Please follow the link for more details explanation.