UICollectionView 及 UICollectionViewCell 复用
来源:互联网 发布:潭州教育java 编辑:程序博客网 时间:2024/06/06 05:17
1、创建:
UICollectionViewFlowLayout *flowLayout =[[UICollectionViewFlowLayoutalloc]init];
flowLayout.scrollDirection =UICollectionViewScrollDirectionVertical;
flowLayout.sectionInset =UIEdgeInsetsZero;
flowLayout.minimumInteritemSpacing =0;
flowLayout.minimumLineSpacing =5;
_collectionView =[[UICollectionViewalloc]initWithFrame:CGRectMake(0,0,self.view.width, [UIScreenmainScreen].bounds.size.height-65)collectionViewLayout:flowLayout];
2、cell复用:
[_collectionViewregisterClass:[ImagePickCollectionViewCellclass]forCellWithReuseIdentifier:cellId];
ImagePickCollectionViewCell *cell = [_collectionViewdequeueReusableCellWithReuseIdentifier:cellIdforIndexPath:indexPath];
3、代理:
#pragma mark ---- UICollectionViewDataSource
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
return1;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
return_photos.count;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
ImagePickCollectionViewCell *cell = [_collectionViewdequeueReusableCellWithReuseIdentifier:cellIdforIndexPath:indexPath];
cell.backgroundColor = [UIColorpurpleColor];
//ALAsset *asset = _photos[indexPath.row];
cell.imageView.image =_photos[indexPath.row];
return cell;
}
#pragma mark ---- UICollectionViewDelegateFlowLayout
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
float wid =CGRectGetWidth(_collectionView.bounds);
returnCGSizeMake((wid -2*5)/3, (wid -2*5)/3);
}
4、注意:
cell 的 frame 不是以(0, 0)开头,添加子View时要注意,否则出现布局错乱。
- UICollectionView 及 UICollectionViewCell 复用
- UICollectionView使用实例(第三方类的使用及自定义UICollectionViewCell)
- UICollectionViewCell复用
- 【UICollectionview】UICollectionViewCell添加阴影书框效果
- iOS UICollectionView 入门 05 创建自定义UICollectionViewCell
- UICollectionView学习<2>之UICollectionViewCell的自定义
- UICollectionView和自定义UICollectionViewCell的基本用法
- 应用集合视图(UICollectionView)-创建UICollectionViewCell子类单元格
- Objective—C实现UICollectionView中UICollectionViewCell的重排实现
- UICollectionViewCell
- UICollectionViewCell
- 获取tableView(UICollectionViewCell)中cell相对于(UICollectionView)tableView.superView的区域坐标(位置)
- UICollectionView的使用方法及demo
- UICollectionView 详解及自定义cell
- UICollectionView的使用方法及demo
- 使用UICollectionView注意事项及用UICollectionView实现图片轮播器
- UICollectionViewCell 布局
- 移动UICollectionViewCell
- lambda函数
- HDU 5961 bfs
- Session 和Cookie 详解
- linux服务器杀死端口命令
- PHP开发异常
- UICollectionView 及 UICollectionViewCell 复用
- c++ 面向对象高效编程 【笔记】什么是数据抽象?
- 如何在腾讯云上开发一款O2O书签?
- A cycle was detected in the build path of project eclipse中target没有classes文件
- 【POJ 1523】SPF(Tarjan求割点)
- Valid Phone Numbers(leetcode193-t5.sh)
- 简介AngularJS中使用factory和service的方法
- java log4j使用
- redis 数据备份