ios - Custom Layout on UICollectionView using Swift 3 -


desire layout on collectionview

i having trouble achieving custom layout on collectionview in swift 3.0. been 2 days searching on similar layout couldn't find one. pls me achieve desire custom layout.

there many ways of doing , there many 3rd party lib out. suspect don't know how layout , spacing among cell.

here best ..just play values similar layout.

override func preparelayout() {  // 1  if cache.isempty { // 2 let columnwidth = contentwidth / cgfloat(numberofcolumns) var xoffset = [cgfloat]() column in 0 ..< numberofcolumns {   xoffset.append(cgfloat(column) * columnwidth ) } var column = 0 var yoffset = [cgfloat](count: numberofcolumns, repeatedvalue: 0)  // 3 item in 0 ..< collectionview!.numberofitemsinsection(0) {    let indexpath = nsindexpath(foritem: item, insection: 0)    // 4   let width = columnwidth - cellpadding * 2   let photoheight = delegate.collectionview(collectionview!, heightforphotoatindexpath: indexpath,        withwidth:width)   let annotationheight = delegate.collectionview(collectionview!,       heightforannotationatindexpath: indexpath, withwidth: width)   let height = cellpadding +  photoheight + annotationheight + cellpadding   let frame = cgrect(x: xoffset[column], y: yoffset[column], width: columnwidth, height: height)   let insetframe = cgrectinset(frame, cellpadding, cellpadding)    // 5   let attributes = uicollectionviewlayoutattributes(forcellwithindexpath: indexpath)   attributes.frame = insetframe   cache.append(attributes)    // 6   contentheight = max(contentheight, cgrectgetmaxy(frame))   yoffset[column] = yoffset[column] + height    column = column >= (numberofcolumns - 1) ? 0 : ++column } 

} }

reference uicollectionview layout


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -