// 初始化瀑布流
UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
[flowLayout setItemSize:CGSizeMake(150,120)]; //设置每个cell显示数据的宽和高必须
flowLayout.sectionInset = UIEdgeInsetsMake(5, 5, 5, 5);
flowLayout.minimumInteritemSpacing = 0;
flowLayout.minimumLineSpacing = 0;
[flowLayout setScrollDirection:UICollectionViewScrollDirectionHorizontal]; //水平滑动
[flowLayout setScrollDirection:UICollectionViewScrollDirectionVertical]; //控制滑动分页用
self.collectionView = [[UICollectionView alloc]initWithFrame:self.view.bounds collectionViewLayout:flowLayout];
[self.view addSubview:self.collectionView];
self.collectionView.backgroundColor = [UIColor whiteColor];
[self.collectionView registerClass:[MyCell class] forCellWithReuseIdentifier:@"COllectioncell"];
[self.collectionView setDataSource:self];
[self.collectionView setDelegate:self];
[self.view addSubview:self.collectionView];
iOS UICollectionView与UITableView,布布扣,bubuko.com
iOS UICollectionView与UITableView
原文地址:http://www.cnblogs.com/longyun/p/3732508.html