Sean256 Sean256 - 2 years ago 548
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 Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download