ios - How can I center rows in UICollectionView? -


i have uicollectionview random cells. there method allows me center rows?

this how looks default:

[ x x x x x x ]   [ x x x x x x ]   [ x x         ]   

here desired layout looks like:

[ x x x x x ]   [ x x x x x ]   [    x x    ]   

a bit of background first - uicollectionview combined uicollectionviewlayout determines how cells placed in view. means collection view flexible (you can create layout it), means modifying layouts can little confusing.

creating entirely new layout class complex, instead want try , modify default layout (uicollectionviewflowlayout) center alignment. make simpler, want avoid subclassing flow layout itself.

here's 1 approach (it may not best approach, it's first 1 can think of) - split cells 2 sections, follows:

[ x x x x x ] <-- section 1  [ x x x x x ] <-- section 1  [    x x    ] <-- section 2  

this should straightforward, provided know width of scroll view , number of cells can fit in each row.

then, use collectionview:layout:insetforsectionatindex: delegate method set margins second section appears vertically centered. once you've done this, need ensure recompute appropriate section divisions/insets both portrait , landscape orientations can supported.

there similar question here - how center align cells of uicollectionview? - goes more details inset methods, although it's not quite trying same thing are.


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -