collectionView纯代码使用
来源:互联网 发布:网络棋牌游戏制作 编辑:程序博客网 时间:2024/05/17 02:42
collectionView和tableView最大的不同之处就是需要自定义cell,所以第一步自定义collectionViewCell
1.自定义collection
//初始化layout
UICollectionViewFlowLayout*flowLayout =[[UICollectionViewFlowLayoutalloc]init];
// 2.设置每个格子的尺寸
flowLayout.itemSize= CGSizeMake(90,90);
// 3.设置整个collectionView的内边距
CGFloat paddingY = 20;
CGFloat paddingX = 20;
flowLayout.sectionInset= UIEdgeInsetsMake(paddingY, paddingX, paddingY, paddingX);
// 4.设置每一行之间的间距
flowLayout.minimumLineSpacing= paddingY;
// flowLayout.headerReferenceSize = CGSizeMake(SCREENWIDTH, 50);//设置headerView的尺寸大小
[flowLayout setScrollDirection:UICollectionViewScrollDirectionVertical];//设置滚动方向
//初始化ConllectionView
_commonConllectionView= [[UICollectionViewalloc]initWithFrame:CGRectMake(0,0,SCREENWIDTH,SCREENHEIGHT)collectionViewLayout:flowLayout];
//注册单元格
[_commonConllectionViewregisterClass:[WCRCommonCollectionViewCellclass]forCellWithReuseIdentifier:@"commonCollectionCell"];
UICollectionViewFlowLayout*flowLayout =[[UICollectionViewFlowLayoutalloc]init];
// 2.设置每个格子的尺寸
flowLayout.itemSize= CGSizeMake(90,90);
// 3.设置整个collectionView的内边距
CGFloat paddingY = 20;
CGFloat paddingX = 20;
flowLayout.sectionInset= UIEdgeInsetsMake(paddingY, paddingX, paddingY, paddingX);
// 4.设置每一行之间的间距
flowLayout.minimumLineSpacing= paddingY;
// flowLayout.headerReferenceSize = CGSizeMake(SCREENWIDTH, 50);//设置headerView的尺寸大小
[flowLayout setScrollDirection:UICollectionViewScrollDirectionVertical];//设置滚动方向
//初始化ConllectionView
_commonConllectionView= [[UICollectionViewalloc]initWithFrame:CGRectMake(0,0,SCREENWIDTH,SCREENHEIGHT)collectionViewLayout:flowLayout];
//注册单元格
[_commonConllectionViewregisterClass:[WCRCommonCollectionViewCellclass]forCellWithReuseIdentifier:@"commonCollectionCell"];
// _commonConllectionView
//注册headerView 此处的ReuserIdentifier 必须和 cellForItemAtIndexPath 方法中一致
[_commonConllectionView registerClass:[*** class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withTeuseIdentifier @“reuableView”];
//设置代理
_commonConllectionView.delegate= self;
_commonConllectionView.dataSource= self;
_commonConllectionView.backgroundColor= [UIColorwhiteColor];
[self.view addSubview:_commonConllectionView];
2.实现3个代理 DataSource,Delegate,DelegateFlowLayout
3.实现代理方法
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView*)collectionView
{
return 1;
}
-(NSInteger)collectionView:(UICollectionView*)collectionView numberOfItemsInSection:(NSInteger)section{
return _commonConllectionArray.count;
}
//定义每个UICollectionView的大小
- (CGSize)collectionView:(UICollectionView*)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath*)indexPath
{
return 1;
}
-(NSInteger)collectionView:(UICollectionView*)collectionView numberOfItemsInSection:(NSInteger)section{
return _commonConllectionArray.count;
}
//定义每个UICollectionView的大小
- (CGSize)collectionView:(UICollectionView*)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath*)indexPath
{
return CGSizeMake(100,100);
}
-(UICollectionViewCell*)collectionView:(UICollectionView*)collectionView cellForItemAtIndexPath:(NSIndexPath*)indexPath{
}
-(UICollectionViewCell*)collectionView:(UICollectionView*)collectionView cellForItemAtIndexPath:(NSIndexPath*)indexPath{
WCRCommonCollectionViewCell *cell = (WCRCommonCollectionViewCell *)[collectionView dequeueReusableCellWithReuseIdentifier:@"commonCollectionCell" forIndexPath:indexPath];
cell.commonInfo= _commonConllectionArray[indexPath.row];
return cell;
return cell;
}
0 0
- collectionView纯代码使用
- 纯代码collectionView(实训)
- CollectionView 使用
- collectionview使用
- 使用纯代码贴
- 纯代码sizeclass使用
- GWT 使用HTML纯代码
- 使用纯代码自定义cell
- 纯代码约束使用AoutLayout
- 使用纯代码绘制CheckBox
- iOS collectionView使用
- collectionview flowLayout使用
- CollectionView的使用
- iOS CollectionView简单使用
- collectionView的使用iOS
- iOS collectionView的使用
- collectionView使用总结
- CollectionView使用入门
- 关于php+mysql+nginx配置的一点总结
- Android拍照、相册 获取图片后,裁剪图片
- Unity3d 简单实现物体旋转缩放移动
- 理解Angular中的$apply()以及$digest()
- bcd码和16进制的区别
- collectionView纯代码使用
- Gradle learn
- pwnable.kr之cmd1
- Android--移植android ndk c++各种兼容性问题
- Spring学习笔记
- [Learning OpenCV](1) OPenCV的结构和内容
- iOS多线程总结
- Android-GestureDetector手势滑动
- poj 2778 DNA Sequence ac自动机+矩阵快速幂