swift - Dynamic Layout iOS with Collection View -


this might simple question -- i'm new ios development.

i have homepage collection view 4 cells take whole screen (top left, top right, bottom left, bottom right) in portrait mode. in landscape mode, want 4 cells side side in row.

is collection view right layout use? should use autoresizing this, or have use other layout constraints?

thank you!

uicollectionview right layout use. can use following making layout

    func collectionview(collectionview: uicollectionview,                     layout collectionviewlayout: uicollectionviewlayout,                     sizeforitematindexpath indexpath: nsindexpath) -> cgsize {      let flowlayout = collectionviewlayout as! uicollectionviewflowlayout     let totalspace = flowlayout.sectioninset.left         + flowlayout.sectioninset.right         + (flowlayout.minimuminteritemspacing * cgfloat(4 - 1))     let size = int((collectionview.bounds.width - totalspace) / cgfloat(4))     return cgsize(width: size, height: size) } 

following way can use inside view controller

class viewcontroller: uiviewcontroller, uicollectionviewdelegate, uicollectionviewdelegateflowlayout {  @objc(collectionview:layout:sizeforitematindexpath:) func collectionview(_ collectionview: uicollectionview,                     layout collectionviewlayout: uicollectionviewlayout,                     sizeforitemat indexpath: indexpath) -> cgsize {      let flowlayout = collectionviewlayout as! uicollectionviewflowlayout     let totalspace = flowlayout.sectioninset.left         + flowlayout.sectioninset.right         + (flowlayout.minimuminteritemspacing * cgfloat(4 - 1))     let size = int((collectionview.bounds.width - totalspace) / cgfloat(4))     return cgsize(width: size, height: size) } } 

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 -