您的位置:首页 > 产品设计 > UI/UE

UICollectionView

2016-01-13 10:23 555 查看

创建

// 先创建瀑布流(官方的)
UICollectionViewFlowLayout *layOut = [[UICollectionViewFlowLayout alloc] init];
// 对每一个用来显示的区域称为item,就是tableView上的cell
// 设置一下item的尺寸
layOut.itemSize = CGSizeMake(100, 160);
// 设置最小行间距(横向滑动时无用)
layOut.minimumLineSpacing = 15;
// 最小列间距(纵向滑动时无用)
layOut.minimumInteritemSpacing = 1;
// 设置距离屏幕上下左右的间距
layOut.sectionInset = UIEdgeInsetsMake(10, 10, 0, 10);
// 滑动方向 (枚举)
layOut.scrollDirection = UICollectionViewScrollDirectionHorizontal;

// 设置flowlayout头部滚动范围
layOut.headerReferenceSize = CGSizeMake(0, 300);

// 创建collectionView
UICollectionView *collection = [[UICollectionView alloc] initWithFrame:self.view.frame collectionViewLayout:layOut];
[self.view addSubview:collection];
collection.dataSource = self;
collection.backgroundColor = [UIColor whiteColor];
// 注册:类似于tableView
[collection registerClass:[MyCollectionViewCell class] forCellWithReuseIdentifier:@"reuse"];


协议方法实现与tableView基本相同

自定义cell与tableView基本相同

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: