I’m trying to display a decoration view behind each row in a UIViewController.
Each “row” has 3 UICollectionViewCells. I’d like to display a background through a decoration view behind the row of three cells.
In viewDidLoad: I am registering the decoration view:
[self.collectionView.collectionViewLayout registerClass:[CollectionRowDecorationView class] forDecorationViewOfKind:@"RowDecorationView"];
I’ve also setup the following delegate method:
- (UICollectionViewLayoutAttributes *)layoutAttributesForDecorationViewOfKind:(NSString *)decorationViewKind atIndexPath:(NSIndexPath *)indexPath
{
UICollectionViewLayoutAttributes *layoutAttributes = [UICollectionViewLayoutAttributes layoutAttributesForDecorationViewOfKind:decorationViewKind withIndexPath:indexPath];
layoutAttributes.frame = CGRectMake(0.0, 0.0, self.collectionView.contentSize.width, self.collectionView.contentSize.height);
layoutAttributes.zIndex = -1;
return layoutAttributes;
}
Unfortunately the delegate method does not get called. I am not 100% clear from reading the documentation what I need to do in order for the decoration view to get initialized? It looks like I am missing another delegate method that needs to get called in order for everything to get setup properly.
Thanks!
You need to add the decorationview in
- (NSArray *)layoutAttributesForElementsInRect:(CGRect)rectlike this: