ios - Uicollectionview weird gap -
i have collection view custom flow layout , wonder why have space (right side):
it may hard notice here, though, may see gray gap between right side , cell.
here how override standard collection view flow layout remove horizontals gaps:
@implementation calendarflowlayout - (nsarray *) layoutattributesforelementsinrect:(cgrect)rect { nsarray *answer = [super layoutattributesforelementsinrect:rect]; nslog(@"layout blck passed"); for(int = 1; < [answer count]; ++i) { uicollectionviewlayoutattributes *currentlayoutattributes = answer[i]; uicollectionviewlayoutattributes *prevlayoutattributes = answer[i - 1]; nsinteger maximumspacing = 0; nsinteger origin = cgrectgetmaxx(prevlayoutattributes.frame); if(origin + maximumspacing + currentlayoutattributes.frame.size.width < self.collectionviewcontentsize.width) { cgrect frame = currentlayoutattributes.frame; frame.origin.x = origin + maximumspacing; currentlayoutattributes.frame = frame; } } return answer; } @end
cell size calculated follow:
- (cgsize)collectionview:(uicollectionview *)collectionview layout:(uicollectionviewlayout *)collectionviewlayout sizeforitematindexpath:(nsindexpath *)indexpath{ return cgsizemake(screen_width/7, (screen_height-navbar_height-status_bar_height)/6); }
those macros above that:
#define screen_width [[uiscreen mainscreen] bounds].size.width
it has been tested , return correct output.
also, if set width screen_width/3, there no gap.
how remove it? why happen?
375 / 3 = 125
375 / 7 = 53.57142857142857
you can't light half pixel, rounding down, leaving gap. make sure size multiple of subview size (or add pixel rightmost object if it's not).
Comments
Post a Comment