Instagram / IGListKit

A data-driven UICollectionView framework for building fast and flexible lists.
https://instagram.github.io/IGListKit/
MIT License
12.84k stars 1.54k forks source link

Getting item size in custom layout #1305

Open Recouse opened 5 years ago

Recouse commented 5 years ago

New issue checklist

How can I get value of - (CGSize)sizeForItemAtIndex:(NSInteger)index; method in my custom UICollectionViewLayout?

popei69 commented 5 years ago

I have a similar issue where my custom UICollectionViewLayout does the size calculation to adapt to the screen (list vs grid), something I'm not sure I want to leave to the ListSectionController and where collectionContext doesn't have enough info anyway.

jassimkm commented 5 years ago

I am trying to do Pinterest layout Any Ideas are welcome

Recouse commented 5 years ago

@jassimkm You can get item size from the adapter with layout delegate. Like this:

extension ViewController: CustomCollectionViewLayoutDelegate {
    func sizeForItem(at indexPath: IndexPath) -> CGSize {
        return adapter.sizeForItem(at: indexPath)
    }
}