UICollectionView set num of colums

I implemented UICollectionViewDelegateFlowLayout on my UICollectionViewController and override the method responsible for determining the size of the Cell. I then took the screen width and divided it with my column requirement. For example, I wanted to have 3 columns on each screen size. So here’s what my code looks like –

– (CGSize)collectionView:(UICollectionView *)collectionView

                  layout:(UICollectionViewLayout *)collectionViewLayout

  sizeForItemAtIndexPath:(NSIndexPath *)indexPath

{

    CGRect screenRect = [[UIScreen mainScreen] bounds];

    CGFloat screenWidth = screenRect.size.width;

    float cellWidth = screenWidth / 3.0; //Replace the divisor with the column count requirement. Make sure to have it in float.

    CGSize size = CGSizeMake(cellWidth, cellWidth);

    return size;

}