UICollectionView for macOS Screen Sizes

I have implemented UICollectionView for iOS / iPadOS and now macOS


But how efficiently I can code collection view for various mac screen/display sizes?


Is there any definite threshold that I can code about? Because there are no compact or regular screen sizes...


Do help me with this...

Did you try setting layout constraints to fit the screen size ?

Actually I want to vary cell numbers horizontally once screen size increases. My cells are square in size so if size dimensions increases horizontal cell should increase in numbers to fit the area.

Is there any specific threshold/benchmark that I can code UICollectionView Cell for window width sizes for macOS e.g. As you know device-width in iOS and iPadOS ecosystem when you load your UI...

Not sure I understand.

But if I did not miss your question, you should:

- you constrain the NSCollection frame size relative to its window (and maybe the window itself is set to occupy full width)

- set a fix size to your cells

Then, it should automaticaaly adapt the number of cells horizontally.

I have used your suggestion of fixed cell size for width and height, but at odd view sizes minimum spacing between two horizontal cells is unpredicatble and which is more than 10... How to manage this spacing between a cell while increasing horizontal cell count?

It depends what is precisely the problem:

I would set the propertiy:

layout.minimumInteritemSpacing = 10

and / or modify the cell width if that's not OK.

with item.size.width


May read this:

https://stackoverflow.com/questions/28325277/how-to-set-cell-spacing-and-uicollectionview-uicollectionviewflowlayout-size-r

Code you shared creates three columns for every size. I want to increase column in numbers when size increases.


I used your idea fixed cell size but it creates unmanageable space between two horizontal cells at certain sizes...

You should show code. Normally, setting the cell width should automatically increase the number of cells displayed.


You could even calculate this size so that horizontal spacing is never more than 10 or 5.

That's a simple math calculation to do.

UICollectionView for macOS Screen Sizes
 
 
Q