Reputation: 11211
I want to create a custom UICollectionViewFlowLayout
to change the way the headers and cells are displayed on the collection view.
I subclassed UICollectionViewFlowLayout
and overridden the layoutAttributesForElementsInRect
method where I create my custom positioned UICollectionViewLayoutAttributes
objects.
The thing is that I am not using [super layoutAttributesForElementsInRect:(CGRect)rect]
to generate the UICollectionViewLayoutAttributes
and because of that my screen is blank.
If I use the [super layoutAttributesForElementsInRect:(CGRect)rect]
method to get the UICollectionViewLayoutAttributes
, the collection view is displayed but in the default way.
I am creating my UICollectionViewLayoutAttributes
using this code:
UICollectionViewLayoutAttributes *cell = [UICollectionViewLayoutAttributes
layoutAttributesForCellWithIndexPath:[NSIndexPath indexPathForRow:item inSection:section]];
[cell setAlpha:self.cellOpacity];
[cell setHidden:NO];
[cell setSize:self.itemSize];
[cell setZIndex:self.cellZIndex];
[cell setFrame:CGRectMake ((self.itemSize.width * item) + self.cellPadding,
(section * self.itemSize.height) + self.cellPadding,
self.itemSize.width,
self.itemSize.height)];
[itemsLayoutAttributes addObject:cell];
Is something wrong with the fact that I am creating the UICollectionViewLayoutAttributes
manually and not using the ones created by the super method?
What do you think I am doing wrong?
Thank you in advance!
Upvotes: 2
Views: 2542
Reputation: 11211
Actually it seems that the only thing I was doing wrong was that I wasn't careful enough to see that the opacity was set to 0 :( .
It seems that my layout now looks alright and indeed one can override layoutAttributesForElementsInRect
method to create and not only edit the UICollectionViewLayoutAttributes
of that flow layout.
Upvotes: 2