Skip to main content

Collection View - 2D Display

/*Nothing but dividing items into number of columns and rows */

sizeForItemAtIndexPath()

It returns the size for each item. In collection view, each cell is considered as item and not as rows or columns.
To make it 2D(columns and rows), distribute the collection view frame size into several item sizes, in such a way that x number of items can be placed in a single row.
For instance, if there are 50 items( 5 items in each row which is nothing but 5 columns in 1 row and there are 10 such rows).  Given collection view frame size is 1000.

Now this can be done by dividing the frame size by number of columns,  i.e., 1000/5 = 200. So each items width will be 200.

Comments