ios - Make UICollectionViewCell appear in center of UICollectionView -
i have cells dynamically added uicollectionview
. change inset of these cells appear in center of uicollectionview
. because more cells added cell height changes (it single row uicollectionview
).
- (uiedgeinsets)collectionview:(uicollectionview*)collectionview layout:(uicollectionviewlayout *)collectionviewlayout insetforsectionatindex:(nsinteger)section { // method used center when 1 tile entered else use standard no inset if (self.wordarray.count == 1) { cgfloat newwidth = (self.tilecollectionview.bounds.size.width - self.tilecollectionview.bounds.size.height); return uiedgeinsetsmake(0, (newwidth / 2), 0, (newwidth/2)); } else { return uiedgeinsetsmake(0, 0, 0, 0); // top, left, bottom, right } }
how reference uicollectionviewcell
current height, of cells shaped same (just height/width changes when more added continue fit 1 row.
once have reference cell height, can add like: self.tilecollectionview.bounds.size.height - cellheight /2 -- use inset cell.
if you're using grid-style layout, i'd try method: collectionview:layout:sizeforitematindexpath:
you'll need implement uicollectionviewflowlayoutdelegate so. them stack, set minimum offsets negatives size of cells themselves. may take trial , error.
Comments
Post a Comment