Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How could I set gradient fixed background on UICollectionView?

I used following code.

CAGradientLayer* collectionRadient = [CAGradientLayer layer];
collectionRadient.bounds = self.collectionView.bounds;
collectionRadient.anchorPoint = CGPointZero;
collectionRadient.colors = [NSArray arrayWithObjects:(id)[startColor CGColor],(id)[endColor CGColor], nil];
[self.collectionView.layer insertSublayer:collectionRadient atIndex:0];

But it drawn on cells included images. so cell was not shown.

I want to draw gradient background of UICollectionView under Cells and fixed it when view scrolled. Let me know Please.

like image 280
nao0811ta Avatar asked Dec 08 '22 09:12

nao0811ta


1 Answers

Try this... You have to assign a view to use background view.

CAGradientLayer* collectionGradient = [CAGradientLayer layer];
collectionGradient.bounds = self.view.bounds;
collectionGradient.anchorPoint = CGPointZero;
collectionGradient.colors = [NSArray arrayWithObjects:(id)[[UIColor redColor] CGColor],(id)[[UIColor greenColor] CGColor], nil];
UIView *vv = [[UIView alloc] init];
vview.backgroundView = vv;
[vview.backgroundView.layer insertSublayer:collectionGradient atIndex:0];
like image 75
Rajesh Choudhary Avatar answered Dec 27 '22 04:12

Rajesh Choudhary