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.
Try this... You have to assign a view to use background view.
In Swift 3.0
I like to start with a custom class for gradients
With the custom class somewhere in the project and added to the target you just need to do as mentioned earlier and add it as a background view rather than background color or separate normal view sent to the back
Implement like so:
Directions
Code Swift 4.2
If you want a top to bottom gradient all you have to do is remove endPoint and startPoint. You can read more about gradients here.
Note that startPoint and endPoint are defined in the coordinate plane from
(0.0, 0.0)
to(1.0, 1.0)