UICollectionView

来源:互联网 发布:分布式 java 编辑:程序博客网 时间:2024/05/17 08:01

创建

// 先创建瀑布流(官方的) 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基本相同

0 0
原创粉丝点击