ios - How to display 3 cells per row in UICollectionView? -
i used custom flow layout according this post. here implementation:
@implementation customlayout -(void)preparelayout{ [super preparelayout]; // [self invalidatelayout]; if(self.collectionview){ cgsize newitemsize=self.itemsize; // number of items per row int itemsperrow=3; float totalspacing=self.minimumlinespacing*(itemsperrow-1); newitemsize.width=(self.collectionview.bounds.size.width -totalspacing)/itemsperrow; if(self.itemsize.height>0){ float itemaspectratio=self.itemsize.width/self.itemsize.height; newitemsize.height=newitemsize.width/itemaspectratio; } [self setitemsize:newitemsize]; } } @end
this i've got: did miss? i've come across other posts no luck far.
//make use of uicollectionviewdelegateflowlayout protocol class rvc: uicollectionviewcontroller { //some code } extension rvc: uicollectionviewdelegateflowlayout{ func collectionview(collectionview: uicollectionview, layout collectionviewlayout: uicollectionviewlayout, sizeforitematindexpath indexpath: nsindexpath) -> cgsize { var collectionviewsize = collectionview.frame.size collectionviewsize.width = collectionviewsize.width/3.0 //display 3 elements in row. collectionviewsize.height = collectionviewsize.height/4.0 return collectionviewsize }
for more information go through below link.
Comments
Post a Comment