On iOS, can you use UICollectionViewFlowLayout to

2019-08-11 09:36发布

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 ]

2条回答
迷人小祖宗
2楼-- · 2019-08-11 10:12

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.

查看更多
冷血范
3楼-- · 2019-08-11 10:27

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

查看更多
登录 后发表回答