On iOS, can you use UICollectionViewFlowLayout to get a vertical column layout?

风流意气都作罢 提交于 2019-12-24 06:59:15

问题


UICollectionViewFlowLayout goes left-to-right in a row, then wraps to the next row. I want a layout that goes top-to-bottom, then wraps back up to the next column. Think of it as a UITableView that wraps into multiple columns, which scrolls horizontally.

UICollectionViewFlowLayout is close to what I want – can I subclass it or must I subclass UICollectionViewLayout and start from scratch? (This answer leads me to believe I can't use flow layout.)

    Visible Screen
    [ 1   6   11 ] 16
    [ 2   7   12 ] 17
    [ 3   8   13 ] 18
    [ 4   9   14 ]
    [ 5   10  15 ]

回答1:


You can achieve it using UICollectionViewFlowLayout - just set the property 'scrollDirection' to 'UICollectionViewScrollDirectionHorizontal' and you get what you want.

About UICollectionViewLayout:

UICollectionViewLayout is meant to be subclassing. You need to override some methods over there in order to get a specific layout. Take a look at the documentation, or WWDC 2012 video tutorial.




回答2:


This might point you in the right direction: https://github.com/chiahsien/UICollectionViewWaterfallLayout

You might want to create your own layout subclass, which is not as hard as it might sound. See this tutorial: http://skeuo.com/uicollectionview-custom-layout-tutorial



来源:https://stackoverflow.com/questions/17298520/on-ios-can-you-use-uicollectionviewflowlayout-to-get-a-vertical-column-layout

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!