ios - Uicollectionview weird gap -


i have collection view custom flow layout , wonder why have space (right side):

enter image description here

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

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

unity3d - Fatal error- Monodevelop-Unity failed to start -