swift - Collectionview with Different items in a row -


okay. collectionview works fine. want change layout bit. have array different numbers array.count = 5 , need 5 items in row. don't know how display in collectionview .

thanks help.

update:

now every row example 6 !

but don't know how handle array of numbers!

func collectionview(collectionview: uicollectionview, layout collectionviewlayout: uicollectionviewlayout, sizeforitematindexpath indexpath: nsindexpath) -> cgsize {          let numberofcellinrow : int = 6         let padding : int = 1         let collectioncellwidth : cgfloat = (self.view.frame.size.width/cgfloat(numberofcellinrow)) - cgfloat(padding)         return cgsize(width: collectioncellwidth, height: 200)    } 

implementing sizeforitematindexpath, part of protocol of uicollectionviewdelegateflowlayout, how set dimensions of uicollectionviewcell dynamically (i.e., @ runtime).

in sizeforitematindexpath, create cgsize object how big you'd each uicollectionviewcell be, , use object return value of function. in example, width of cgsize object approximately width of main view divided 5. approximately because need room padding between cells perhaps non-zero sectioninsets around each section of uicollectionview.

to set padding between cells, go attributes inspector pane in storyboard uicollectionview object, , put attributes pane in "measurements mode". you'll see "min spacing", both "for cells" , "for lines". "for cells" field can specify horizontal spacing you'd between cells. "for lines" field can specify vertical spacing you'd between cells.


Comments

Popular posts from this blog

many to many - Django Rest Framework ManyToMany filter multiple values -

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

Java Entity Manager - JSON reader was expecting a value but found 'db' -