UICollectionView Flow layout no fixed row height

2020-03-31 02:23发布

How to modify the flow layout, so that there is the same vertical spacing between the smaller and larger cells (eg. there is no fixed row height / the row height is not fixed to the maximal size)?

enter image description here

I want to look it like this

enter image description here

1条回答
狗以群分
2楼-- · 2020-03-31 02:55

The solution was using UICollectionViewWaterfallLayout

Follow the setup from the website, and you can setup it like this

- (void)viewDidLoad
{
    [super viewDidLoad];

    UICollectionViewWaterfallLayout * layout = (UICollectionViewWaterfallLayout *)self.collectionView.collectionViewLayout;
    layout.delegate = self;
    layout.columnCount = 2;
    layout.itemWidth = 150.f;
    layout.sectionInset = UIEdgeInsetsZero;

    ...
}
查看更多
登录 后发表回答