2019独角兽企业重金招聘Python工程师标准>>>
#pragma marc 添加Collection
-(void)addConllectionView{//collection的布局方案UICollectionViewFlowLayout *collectionViewLayout=[[UICollectionViewFlowLayout alloc]init];//设置位置大小以及布局方案_myCollectionView=[[UICollectionView alloc]initWithFrame:CM(0, 0, VIEW_WIDTH,VIEW_HEIGHT-64-48) collectionViewLayout:collectionViewLayout];//CollectionView的背景颜色_myCollectionView.backgroundColor=[UIColor whiteColor];[self addSubview:_myCollectionView];//设置代理_myCollectionView.delegate=self;_myCollectionView.dataSource=self;//注册Cell 以及选择控制的类[_myCollectionView registerClass:[ExhibitionCollectionViewCell class] forCellWithReuseIdentifier:@"cell"];//注册Head以及Food 以及选择控制的类[_myCollectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"Head"];}
#pragma mark 设置Cell
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{ExhibitionCollectionViewCell *cell=[_myCollectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];cell.backgroundColor=[UIColor whiteColor];cell.imageView.image=[UIImage imageNamed:@"商品"];return cell;
}
#pragma mark 设置头部以及尾部
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
{if ([kind isEqualToString:UICollectionElementKindSectionHeader]) {//和判断复用一样UICollectionReusableView * head = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"Head" forIndexPath:indexPath];//添加轮播图[head addSubview:_carouselFigureView];return head;}return nil;}
#pragma mark 设置Cell返回数量
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{return 20;
}
#pragma mark 定义展示的组数
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{return 1;
}#pragma mark 设置cell的大小
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{return CGSizeMake(VIEW_WIDTH/3.55f, VIEW_HEIGHT/3.550f);}#pragma mark 设置每个section中不同的行之间的行间距
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section
{return 20;
}
#pragma mark 设置每个section中不同的列之间的间距
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section
{return 10;
}
#pragma mark 设置每个Cell的内边距
-(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{return UIEdgeInsetsMake(0, 0, 10, 0);//分别为上、左、下、右
}
#pragma mark 点击事件
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{CommodityDisplayControllerView * CDVC=[[CommodityDisplayControllerView alloc]init];[[self getController] presentViewController:CDVC animated:YES completion:nil];NSLog(@"%ld",indexPath.row);
}#pragma mark 返回头headerView的大小
-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section{CGSize size={VIEW_WIDTH,IMG_EXHIBITION_HEIGHT};return size;
}