1

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)

enter image description here

Appygix
  • 642
  • 12
  • 26

2 Answers2

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