I want to create a 3 columns with a UICollectionView, Here is the code I did: I have attached a UICollectionViewFlowLayout to my UICollectionView and I set the itemSize to be collection view's width divides by 3:
self.collectionView.backgroundColor = [UIColor blueColor];
UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
double width = self.collectionView.frame.size.width;
width /= 3;
[flowLayout setItemSize:CGSizeMake(width, 100)];
[flowLayout setScrollDirection:UICollectionViewScrollDirectionHorizontal];
[self.collectionView setCollectionViewLayout:flowLayout];
But when I run it, I only see 1 item per row but the width of the item is set correctly. The right of the item is a bunch of white spaces.
Can you please tell me what am I missing?
Thank you.
Update:
I have tried this with minimum spacing set. But that still does not work. I only see 1 column of cells:
self.collectionView.backgroundColor = [UIColor blueColor];
UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
[flowLayout setItemSize:CGSizeMake(160, 160)];
[flowLayout setScrollDirection:UICollectionViewScrollDirectionHorizontal];
flowLayout.minimumInteritemSpacing = 10.0f;
flowLayout.minimumLineSpacing = 10.0f;
[self.collectionView setCollectionViewLayout:flowLayout];
When I adjust the spacing values in the code, I see the spacing on the screen changes. It is just that it only layout the cell in 1 column. Instead of 2