Here is the programmatic answer to your question:
Create a class by extending UICollectionViewFlowLayout .
In the implementation file of our class, add the following methods:
- (instancetype)init
{
self = [super init];
if (self) {
//overriding default values
self.scrollDirection = UICollectionViewScrollDirectionVertical;
self.minimumInteritemSpacing = 0;
self.minimumLineSpacing = 0;
}
return self;
}
//Method to arrange ur cells properly
- (NSArray *) layoutAttributesForElementsInRect:(CGRect)rect {
//Returns an array of UICollectionViewLayoutAttributes objects representing the layout information for the cells and views.
NSArray *attribArray = [super layoutAttributesForElementsInRect:rect];
for(int i = 1; i < [attribArray count]; ++i) {
UICollectionViewLayoutAttributes *currentLayoutAttributes = attribArray[i];
UICollectionViewLayoutAttributes *prevLayoutAttributes = attribArray[i - 1];
//No separation between the cells
NSInteger maximumSpacing = 0;
NSInteger origin = CGRectGetMaxX(prevLayoutAttributes.frame);
if((origin + maximumSpacing + currentLayoutAttributes.frame.size.width) < self.collectionViewContentSize.width) {
CGRect frame = currentLayoutAttributes.frame;
frame.origin.x = origin + maximumSpacing;
currentLayoutAttributes.frame = frame;
}
}
return attribArray;
}
//If collection view bound changes, it will recompute all of its layout attributes
- (BOOL)shouldInvalidateLayoutForBoundsChange:(CGRect)newBounds
{
return YES;
}
Set this custom class as a flow layout to your collection view,
YourFLowLayoutCustomClass *flowlayout=[[YourFLowLayoutCustomClass alloc] init];
_collectionView = [[UICollectionView alloc]initWithFrame:frame collectionViewLayout:flowlayout];
Now in the class where you have implemented the UICollectionView, implement the following method if you have not already done it:
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
return CGSizeMake(self.view.frame.size.width/2, self.view.frame.size.height/3);
}
This will set the size of the cells as per the Picture you shared. Cheers!