ios - UICollectionView: add spacing between header and items -
i want add spacing between header , actual items, this:
func collectionview(collectionview: uicollectionview, viewforsupplementaryelementofkind kind: string, atindexpath indexpath: nsindexpath) -> uicollectionreusableview { // create header switch kind{ case uicollectionelementkindsectionheader: let headerview = iconcollectionview.dequeuereusablesupplementaryviewofkind(kind, withreuseidentifier: "customiconheaderview", forindexpath: indexpath) as! custoniconheaderview headerview.setup() //add whatever view return headerview default: assert(false, "unexpected element kind") } }
you talking adding top margin collection view section, set top inset section. in code, implement insetforsectionatindex
:
func collectionview(collectionview: uicollectionview, layout collectionviewlayout: uicollectionviewlayout, insetforsectionatindex section: int) -> uiedgeinsets { return uiedgeinsets(top: 10.0, left: 1.0, bottom: 1.0, right: 1.0) }
if don't want implement insetforsectionatindex
, in appropriate method e.g. viewdidload
:
let layout = collectionview.collectionviewlayout as! uicollectionviewflowlayout layout.sectioninset = uiedgeinsets(top: 10.0, left: 1.0, bottom: 1.0, right: 1.0)
in interface builder, select collection view , change value section insets -> top shown in image below:
note: works if using flow layout.
Comments
Post a Comment