ios - Autoresizing of cells in UICollectionViewCell in accordance with the frame size -


how can make cells in collection view auto resize minimum of 4 cells can @ least fit in single row, , if frame size of ipad, more cells fit in row. 4 cells should minimum number of cells in row, please see pictures below further clarification:

i have collection view allows me add images using picker view controller, @ first collection view looks this:

enter image description here

i can further add images collection view , after adding several images, like:

enter image description here

right if there 4 images, fourth 1 goes next row, want system autoresize cells based on frame size minimum 4 cells shown in 1 row. i'm newbie , quite new collection view, can please me on this?

you can decide size of collectionview's cell using following method:

func collectionview(_ collectionview: uicollectionview, layout collectionviewlayout: uicollectionviewlayout, sizeforitemat indexpath: indexpath) -> cgsize{      // return different cells size     let screenbounds = uiscreen.main.bounds     var width = screenbounds.width     let totalleftrightinsect = 16           let minimumsspacebetweencell = 5      switch (condition detecting device ) {     case "iphone":         let numberofcell = 4          let totalspace = cgfloat(( numberofcell * spacebetweencell) + totalleftrightinsect)         width = (width - totalspace) / cgfloat(numberofcell)         return cgsize(width: width, height: width)      case "ipad":          let numberofcell = 6          let totalspace = cgfloat(( numberofcell * spacebetweencell) + totalleftrightinsect)         width = (width - totalspace) / cgfloat(numberofcell)         return cgsize(width: width, height: width)      default:         return cgsize(width: 0.0, height: 0.0)     }} 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -