ios - UICollectionView: add spacing between header and items -


i want add spacing between header , actual items, this:

screenshot1

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:

enter image description here

note: works if using flow layout.


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -