How to set opacity on UICollectionView background without affect opacity of UICollectionViewCell?

Use the -colorWithAlphaComponent: method of UIColor:

[self.collectionView setBackgroundColor:[[UIColor redColor] colorWithAlphaComponent:0.5]];

This will result in only the background having a non-1 alpha value.


If you only want to change the opacity without changing the color or need to keep track of the color itself, you can use:

self.collectionView.backgroundColor = [self.collectionView.backgroundColor colorWithAlphaComponent:0.5f];

There are two possible "backgrounds" on UICollectionView that you may want to change the opacity of. The backgroundColor property is the simplest, but only changes the full color background. There's also the backgroundView which can have subviews which will not change opacity if you just change the background color opacity. You can change the opacity of the backgroundView with:

self.collectionView.backgroundView.alpha = 0.5f;