ios - Spacing in CollectionView Cells -
how remove spacing in collectionview cells. want 18 rows , 22 columns should fit according frame height , width. override uicollectionviewflowlayout there space after last column in collection view. can 1 please me solve this.
there 2 ways it----
- (void)didreceivememorywarning { [super didreceivememorywarning]; // dispose of resources can recreated. } #pragma mark - collection view -(nsinteger)numberofsectionsincollectionview:(uicollectionview *)collectionview { return 1; } -(nsinteger)collectionview:(uicollectionview *)collectionview numberofitemsinsection:(nsinteger)section { return 30; } -(uicollectionviewcell *)collectionview:(uicollectionview *)collectionview cellforitematindexpath:(nsindexpath *)indexpath { magazinecell *mcell = (magazinecell *)[collectionview dequeuereusablecellwithreuseidentifier:cellid forindexpath:indexpath]; mcell.backgroundcolor = [uicolor lightgraycolor]; return mcell; } #pragma mark collection view layout things // layout: set cell size - (cgsize)collectionview:(uicollectionview *)collectionview layout:(uicollectionviewlayout*)collectionviewlayout sizeforitematindexpath:(nsindexpath *)indexpath { nslog(@"setting size item @ index %d", indexpath.row); cgsize melementsize = cgsizemake(104, 104); return melementsize; } - (cgfloat)collectionview:(uicollectionview *)collectionview layout:(uicollectionviewlayout*)collectionviewlayout minimuminteritemspacingforsectionatindex:(nsinteger)section { return 0.0; } - (cgfloat)collectionview:(uicollectionview *)collectionview layout:(uicollectionviewlayout*)collectionviewlayout minimumlinespacingforsectionatindex:(nsinteger)section { return 2.0; } // layout: set edges - (uiedgeinsets)collectionview: (uicollectionview *)collectionview layout:(uicollectionviewlayout*)collectionviewlayout insetforsectionatindex:(nsinteger)section { // return uiedgeinsetsmake(0,8,0,8); // top, left, bottom, right return uiedgeinsetsmake(0,0,0,0); // top, left, bottom, right } @end
and other way--------> 1.override standard flow layout. 2.add implementation that:
- (nsarray *) layoutattributesforelementsinrect:(cgrect)rect { nsarray *answer = [super layoutattributesforelementsinrect:rect]; 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; }
Comments
Post a Comment