I have subclassed flow layout and set it as my collectionViewLayout
on my collection view.
Then I set up the layout as follows:
- (id) init
{
if(self = [super init])
{
self.minimumInteritemSpacing = 11.0;
self.scrollDirection = UICollectionViewScrollDirectionVertical;
self.itemSize = CGSizeMake(64.0,32.0);
self.minimumLineSpacing = 10.0;
self.sectionInset = UIEdgeInsetsMake(11.0,95.0,11.0,11.0);
return self;
}
return nil;
}
95 + 64 + 11 + 64 + 11 + 64 + 11 = 320 - i checked it. (thats one left inset, 3 cells, 2 spaces and one right inset)
I have 1 section, 72 items, and my cell for index path function:
- (UICollectionViewCell*) collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
CustomCell *cell = [self.collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifierForCustomCell forIndexPath:indexPath];
cell.mainLabel.text = [@(indexPath.item) stringValue];
return cell;
}
The output is this:
As you can see, there's just 2 cells per row. Furthermore, it is not displaying every 3rd cell.
I had a look at what flow layout's layout function was producing
- (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect {
gives...
This is the first 3 layout attributes in the layoutAttributes [NSArray]
and as you can see it has decided to only deem the first 2 and then the 4th item as visible for the rect (320 by 568). This has to be an error in collection view layout, doesn't it? The collection view fills the screen and is 320 wide. So since this is a line breaking layout, no items should be off screen.
With edge insets removed:
It works as it is supposed to. But I would like to have section insets since I need to add some decoration views which need to be in the same scroll view while I need a much bigger lleft inset than right inset.