UICollectionView Grid Column Break

I use the UICollectionView layout in my iPad application. I have cells with different widths and heights. When I used the UICollectionViewFlowLayout subclass as a layout to represent the collection, it shows spaces between cells.

If there is a large cell in the column, it draws a grid and small cells in that column to get the rendering centered by that big cell in the column. Is there a better way to rigidly pack cells?

I use horizontal scrolling. I tried using the layoutAttributesForElementsInRect: method, but could not succeed.

Please let me know if someone has done the same using the layoutAttributesForElementsInRect: method or in another way ...

Please find the attached image. I need the same solution enter image description here

Thanks in advance...

+7
source share
2 answers

Use as

 UICollectionViewFlowLayout *layout=[[UICollectionViewFlowLayout alloc] init]; layout.minimumInteritemSpacing = 0; layout.minimumLineSpacing = 2; 
+1
source

I have subclassed UICollectionViewFlowLayout and in both my layoutAttributesForItemAtIndexPath: and layoutAttributesForElementsInRect: methods I have one method called

 setLineAttributes:(UICollectionViewLayoutAttributes *)attributes visibleRect:(CGRect)visibleRect: 

which contains:

 if (attributes.indexPath.item == 0 || attributes.indexPath.item == 1 || attributes.indexPath.item == 2) { CGRect f = attributes.frame; f.origin.x = 0; attributes.frame = f; } else { NSIndexPath *ipPrev = [NSIndexPath indexPathForItem:attributes.indexPath.item - 3 inSection:attributes.indexPath.section]; CGRect fPrev = [self layoutAttributesForItemAtIndexPath:ipPrev].frame; CGFloat rightPrev = fPrev.origin.x + fPrev.size.width + 10; if (attributes.frame.origin.x <= rightPrev) return; CGRect f = attributes.frame; f.origin.x = rightPrev; attributes.frame = f; } 
0
source

All Articles