Cauchy Kun Cauchy Kun - 1 year ago 169
Objective-C Question

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

I have set the color of a

with an
pattern like so:

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

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

Thanks for any tips.

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download