How could I set gradient fixed background on UICollectionView?

gradient, ios, objective-c, uicollectionview

Solution

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];

Problem

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.

Original source