apploft / APLExpandableCollectionView

UICollectionView subclass with vertically expandable and collapsible sections
MIT License
110 stars 14 forks source link

collectionViewLayout:sizeForItemAtIndexPath: doesn't work! #5

Closed Elmundo closed 9 years ago

Elmundo commented 9 years ago

Hi,

I'm trying to change size of individual collection view cell's using "collectionViewLayout:sizeForItemAtIndexPath:" method but it always override it with layout.itemSize value.

itemSize: 375,40 sizeForIndexPath method return size of item which is (50,50). When i check the cell size it's (375,40) again.

Help please..

michaelkamphausen commented 9 years ago

Hi!

You could set layout.itemSize = CGSizeMake(50, 50) and therefore change the size of all your cells.

This component is build with the assumption that every cell has basically the same size to keep things simple. If you are trying a more complex layout with different cell sizes using "collectionViewLayout:sizeForItemAtIndexPath:" you will need to subclass APLSectionTopToBottomFlowLayout with your own implementation.

ininex commented 8 years ago

Can you provide a tutorial on how to subclass APLSectionTopToBottomFlowLayout? I'm not really sure on what function to override but I really need to adjust cell height bases on the different cell types. Thanks.

michaelkamphausen commented 8 years ago

My preferred approach would be to set the delegate of your APLExpandableCollectionView to an object that implements the UICollectionViewDelegateFlowLayout protocol method collectionView:layout:sizeForItemAtIndexPath:. In your implementation you return the desired size. Now look into APLSectionTopToBottomFlowLayout.m: In your APLSectionTopToBottomFlowLayout subclass you'll need to override all the methods that use itemSize for a specific NSIndexPath and use the return value from your new delegate method instead of itemSize. That's at least layoutAttributesForElementsInRect and layoutAttributesForItemAtIndexPath in conjunction with applySectionTopToBottomLayoutAttributes as well as pointForIndexPath. Maybe even prepareLayout needs to be reimplemented, in that case you might end up with a complete reimplementation of APLSectionTopToBottomFlowLayout.