Do like this :
func collectionView(collectionView: UICollectionView,
layout collectionViewLayout: UICollectionViewLayout,
sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize
{
collectionData.contentInset=UIEdgeInsetsMake(0,0,0,0)
let screensize:CGRect=UIScreen.mainScreen().bounds
let width=screensize.width
if (width==320)
{
let size:CGSize=CGSizeMake(129,140)
collectionData.contentInset=UIEdgeInsetsMake(0,10,0,10)
return size
}
else if(width==375)
{
let size:CGSize=CGSizeMake(166,181)
collectionData.contentInset=UIEdgeInsetsMake(0,0,0,0)
return size
}
else if(width==414)
{
if(UIDevice.currentDevice().orientation .isLandscape)
{
let size:CGSize=CGSizeMake(300,185)
collectionData.contentInset=UIEdgeInsetsMake(0,0,0,0)
print("com,ing inside orientatiom");
return size
}
let size:CGSize=CGSizeMake(177,185)
collectionData.contentInset=UIEdgeInsetsMake(0,0,0,0)
return size
}
let size:CGSize=CGSizeMake(358,292)
return size
}