ios - In UICollectionViewCell need to set border effect where it cross to each others (Junction type) -
i implement uicollectionviewcell. need set border effect cell cross each others junction point.
here image, need set border this..
i tried out give cell border in output left & right side border appear not desired output. output this. (wrong output)
so please me..
note: below answer based on discussion between question owner , myself.
you need setup collectionviewflowlayout
achieve desired output. try below code:
func collectionview(_ collectionview: uicollectionview, layout collectionviewlayout: uicollectionviewlayout, sizeforitematindexpath indexpath: indexpath) -> cgsize { // values changable according needs. let layout = collectionview.collectionviewlayout as! uicollectionviewflowlayout layout.sectioninset = uiedgeinsets.zero layout.minimuminteritemspacing = 1 layout.minimumlinespacing = 2 return cgsize(width: (self.collectionview.frame.width / 2) - 1 , height:(self.collectionview.frame.height / 3) - 1) }
update 1: calculating layout includes navigationbar
, statusbar
.
func collectionview(_ collectionview: uicollectionview, layout collectionviewlayout: uicollectionviewlayout, sizeforitematindexpath indexpath: indexpath) -> cgsize { // values changable according needs. let layout = collectionview.collectionviewlayout as! uicollectionviewflowlayout layout.sectioninset = uiedgeinsets.zero layout.minimuminteritemspacing = 1 layout.minimumlinespacing = 2 return cgsize(width: (self.collectionview.frame.width / 2) - 1 , height:(((self.view.frame.height - ((navigationcontroller?.navigationbar.frame.height)! + uiapplication.shared.statusbarframe.height)) / 3) - 1)) }
you may need validate collectionview frame in viewdidlayoutsubviews
or viewwilllayoutsubviews
override func viewdidlayoutsubviews() { collectionview.frame = cgrect(x: 0, y: 0, width: view.frame.width, height: view.frame.height) }
following link may understand collectionviewflowlayout
.
enforce collectionview have 2 rows
uicollectionview remove top padding
note: in future, post question relevant code , state problem clearly.
Comments
Post a Comment