Sean256 Sean256 - 6 months ago 257
Swift Question

Override NSCollectionView item size

So I have a collection view rendering with sections and items. I am using flowLayout and set the default item size like so:

flowLayout.itemSize = NSSize(width: 64.0, height: 128.0)


According to the documentation, "...The collection view’s delegate can override the default size values and specify different values for each item."

How do I do this?

Answer

Quoting the documentation,

This property [itemSize] contains the default size of items. If you do not provide an estimated size or implement the collectionView:layout:sizeForItemAtIndexPath: method in your delegate, the flow layout uses this value for the size of each item.

So you can simply implement this delegate method to return a different size for each item if desired.

You may also wish to read about the estimatedItemSize property.

Comments