If you want to change the opacity without changing the color, or you need to track the color itself, you can use:
self.collectionView.backgroundColor = [self.collectionView.backgroundColor colorWithAlphaComponent:0.5f];
There are two possible โbackgroundsโ in the UICollectionView that you can change the opacity. The backgroundColor property is the simplest, but only changes the full-color background. There's also a backgroundView , which may have subviews that won't change transparency if you just change the opacity of the background color. You can change the opacity of the backgroundView with:
self.collectionView.backgroundView.alpha = 0.5f;
Fennelouski
source share