集合视图基本代码

创建集合视图
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
layout.itemSize = CGSizeMake(item_W, item_H);
layout.minimumLineSpacing = 15;
layout.minimumInteritemSpacing = item_padding;
layout.sectionInset = UIEdgeInsetsMake(15, 12, 15, 12);//top, left, bottom, right
layout.headerReferenceSize = CGSizeMake(CGRectGetWidth(self.view.frame), 40);
layout.footerReferenceSize = CGSizeMake(CGRectGetWidth(self.view.frame), 10);
self.collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.view.frame), CGRectGetHeight(self.view.frame)) collectionViewLayout:layout];
self.collectionView.delegate = self;
self.collectionView.dataSource = self;
[self.view addSubview:self.collectionView];
self.collectionView.backgroundColor = [UIColor whiteColor];

[self.collectionView registerClass:[GoodsReclassifyCell class] forCellWithReuseIdentifier:GoodsReclassifyCellIdentifier];
[self.collectionView registerClass:[ToolHeaderView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:ToolHeaderViewIdentifier];
[self.collectionView registerClass:[GoodsReclassFootView class] forSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:GoodsReclassFootViewIdentifier];
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容