i using lbtacomponents
pod pod makes easier work uicollectionview
without need register , provides super simple anchoring system ... , in first project i've got 2 days ago decided use framework have problem in 1 of uicollectionviewcells
need collectionview
can fill items need scrollable horizontally
import lbtacomponents import uikit class productcell: datasourcecell { let cellid = "cellid" let collectionview : uicollectionview = { let layout = uicollectionviewflowlayout() let cv = uicollectionview(frame: .zero, collectionviewlayout: layout) cv.backgroundcolor = .black return cv }() override func setupviews() { super.setupviews() productcell.addsubview(collectionview) collectionview.frame = frame collectionview.register(uicollectionview.self, forcellwithreuseidentifier: cellid) collectionview.datasource = self } } extension productcell : uicollectionviewdatasource{ func collectionview(_ collectionview: uicollectionview, numberofitemsinsection section: int) -> int { return 5 } func collectionview(_ collectionview: uicollectionview, cellforitemat indexpath: indexpath) -> uicollectionviewcell { let cell = collectionview.dequeuereusablecell(withreuseidentifier: cellid, for: indexpath) cell.backgroundcolor = .white return cell } }
datasourcecell
equal uicollectionviewcell
in pod.
and getting error :
instance member 'addsubview' cannot used on type uiview did use value of type instead?
could please me?
i tried use self.addsubview(collectionview)
but got error enter image description here
you can use uitableview
custom uitableviewcells
containing uicollectionview
.
example:
1. view hierarchy
2. uiviewcontroller
containing uitableview
class viewcontroller: uiviewcontroller, uitableviewdatasource, uitableviewdelegate { func tableview(_ tableview: uitableview, numberofrowsinsection section: int) -> int { return 2 } func tableview(_ tableview: uitableview, cellforrowat indexpath: indexpath) -> uitableviewcell { return tableview.dequeuereusablecell(withidentifier: "tcell", for: indexpath) as! tablecell } func tableview(_ tableview: uitableview, heightforrowat indexpath: indexpath) -> cgfloat { if indexpath.row == 0 { return 120 } else { return 150 } } }
3. custom uitableviewcell
containing uicollectionview
class tablecell: uitableviewcell, uicollectionviewdatasource { func collectionview(_ collectionview: uicollectionview, numberofitemsinsection section: int) -> int { return 3 } func collectionview(_ collectionview: uicollectionview, cellforitemat indexpath: indexpath) -> uicollectionviewcell { return collectionview.dequeuereusablecell(withreuseidentifier: "ccell", for: indexpath) } }
4. output screenshot
Comments
Post a Comment