ios - Creating a 2 x 2 Horizontal Grid in UICollectionView? -
i have popover has uicollectionviewcontroller. i'm trying make 2 x 2 grid it's showing 1 row. want 2 rows.
i attempted divide uicollectionview frame number of rows, still shows 1 row.
func collectionview(collectionview: uicollectionview, layout collectionviewlayout: uicollectionviewlayout, sizeforitematindexpath indexpath: nsindexpath) -> cgsize { let itemwidth = cgrectgetwidth(collectionview.frame) let itemheight = cgrectgetheight(collectionview.frame) let squaresizeheight = itemheight / 2 let squaresizewidth = itemwidth / 2 return cgsizemake(squaresizewidth, squaresizeheight) }
(note: made popover big on purpose)
he need set min spacing , section inset value zero
and if want show spacing between 2 cell use below formula
func collectionview(collectionview: uicollectionview, layout collectionviewlayout: uicollectionviewlayout, sizeforitematindexpath indexpath: nsindexpath) -> cgsize { let itemwidth = cgrectgetwidth(collectionview.frame) - spacingvalue let itemheight = cgrectgetheight(collectionview.frame) - spacingvalue let squaresizeheight = itemheight / 2 let squaresizewidth = itemwidth / 2 return cgsizemake(squaresizewidth, squaresizeheight) }
Comments
Post a Comment