ios - Auto-sizing UICollectionView headers -


i'm trying make detail screen to-do list kind of app. here's detail screen looks like:

detail screen

this uicollectionviewcontroller, header. header contains 2 uilabel objects, , uitextview object. layout of these objects managed vertical uistackview. uiview used set white background.

i'm having difficulties in defining height of uicollectionreusableview @ runtime. advice appreciated.

here how can handle custom uicollectionviewreusableview auto layout without xib file.

  1. implement referencesizeforheaderinsection delegate method.
  2. in it, instantiate view use header view.
  3. set visibility hidden, avoid flashing.
  4. add view collectionview's superview.
  5. set it's layout using auto layout, match expected visual outcome of header.
  6. invoke setneedslayout , layoutifneeded
  7. remove view superview

caution: not big fan of solution, adds custom view collectionview's superview each time, perform calculations. didn't notice performance issues though.

caution #2: i'd treat temporary solution, , migrate self sizing supplementary views once published.

i using purelayout autolayout purposes.

func collectionview(_ collectionview: uicollectionview, layout collectionviewlayout: uicollectionviewlayout, referencesizeforheaderinsection section: int) -> cgsize {      let header = customheaderview()          header.ishidden = true;         self.view.addsubview(header)         header.autopinedge(tosuperviewedge: .leading)         header.autopinedge(tosuperviewedge: .trailing)         header.autopin(totoplayoutguideof: self, withinset: 0)         header.setupheader(withdata: self.data)         header.setneedslayout()         header.layoutifneeded()         header.removefromsuperview()          return header.frame.size } 

Comments

Popular posts from this blog

amazon web services - S3 Pre-signed POST validate file type? -

c# - Check Keyboard Input Winforms -