My best idea to fix this is to somehow say each cell if it is in the last line of a section or the last cell in a line; then the cell will disable the violating borders, in the section headings there will be an upper border, as well as a bottom, and everything will be hard. I do not know how to achieve this.
What you are describing is more or less what I did in a similar scenario. I added the border property to my cell:
typedef NS_OPTIONS(NSInteger, TLGridBorder) { TLGridBorderNone = 0, TLGridBorderTop = 1 << 0, TLGridBorderRight = 1 << 1, TLGridBorderBottom = 1 << 2, TLGridBorderLeft = 1 << 3, TLGridBorderAll = TLGridBorderTop | TLGridBorderRight | TLGridBorderBottom | TLGridBorderLeft, }; @interface TLGridCellView : UIView @property (nonatomic) TLGridBorder border; @end
Then I set the border in my controller controller configuration:
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { TLGridCellView *cell = ...; if (indexPath.item == self collectionView:collectionView numberOfItemsInSection:indexPath.section - 1) { cell.border = TLGridBorderLeft; } else { cell.border = TLGridBorderLeft | TLGridBorderRight; } return cell; }
source share