2

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!

Cata
  • 11,133
  • 11
  • 65
  • 86
  • check a similar answer that is all about manipulating UICollectionViewFlowLayout: http://stackoverflow.com/questions/19712201/ios-uicollectionview-default-flow-fill-rows-from-right-to-left/19923873#19923873 you can +1 if it helps :) – Raz Jan 14 '14 at 09:22
  • you can also try this one: http://stackoverflow.com/questions/19474667/uicollectionview-cell-starting-margin these are all working examples :) – Raz Jan 14 '14 at 09:25
  • Thank you very much Raz but I found the issue, you can read it below and it is embarrassing.. I know.. – Cata Jan 14 '14 at 17:42

1 Answers1

2

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.

Cata
  • 11,133
  • 11
  • 65
  • 86