I have a UICollectionView
and only one section. Is there a way to set the background color of every row? (in my case it would be a gradient from black to white)
Asked
Active
Viewed 872 times
1

Appygix
- 642
- 12
- 26
2 Answers
1
CollectionViews don't really have a concept of a rows because it's designed to have a flexible layout.
Your best option is likely to have the background of the cells have your pattern and remove all the padding/margin between the cells.
This will be a problem if the last row isn't full, so if the number needs to be flexible you would have to add empty cells.

GetSwifty
- 7,568
- 1
- 29
- 46
-
If you're going to have a consistent layout, you might consider using a tableView instead. – GetSwifty May 20 '16 at 17:12
-
I have/need a UICollectionView - its only about the design – Appygix May 20 '16 at 18:08
0
You can set on color on cell using cell.backgroundColor = [UIColor magentaColor];
else for gradient you have to layer and set to cell like below code
CAGradientLayer *gradient = [CAGradientLayer layer];
gradient.frame = cell.bounds;
gradient.colors = [NSArray arrayWithObjects:(id)[[UIColor whiteColor] CGColor], (id)[[UIColor blackColor] CGColor], nil];
[cell.layer insertSublayer:gradient atIndex:0];

JP_Mob
- 114
- 7