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)

enter image description here

he need set min spacing , section inset value zero

enter image description here

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

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -