Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I have set the color of a UICollectionView with an image pattern like so:

self.collectionView.backgroundColor = [UIColor colorWithPatternImage:image];

I would like to set the alpha of the collectionView without affecting the alpha of the UICollectionViewCell. Is there a way to do this? Setting the alpha of collectionView also affects the UICollectionViewCell, so I already tried that. What else should I try/what else will actually work?

Thanks for any tips.

like image 937
Cauchy Kun Avatar asked Jul 01 '15 21:07

Cauchy Kun


1 Answers

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.

like image 87
rebello95 Avatar answered Sep 28 '22 09:09

rebello95