collectionview使用
创建UICollectionViewFlowLayout 对象来设置相关的布局,包括itemSize,headerReferenceSize,sectionInset。设置对应的布局大小,相关的和顶部之间的间距等。
UICollectionView创建对应的view并且定义对应的大小,设置代理方法和数据源对象。
-(void)loadCollectionView
{
UICollectionViewFlowLayout * collectionViewFlow = [[UICollectionViewFlowLayout alloc]init];
UICollectionView *collectView = [[UICollectionView alloc]initWithFrame:CGRectMake(, ScreenHeight, CGRectGetWidth(_homeScrollView.frame), )collectionViewLayout:collectionViewFlow]; collectView.dataSource = self;
collectView.delegate = self;
collectView.backgroundColor = [UIColor blueColor];
[collectView registerClass:[CSHomeCollectionViewCell class] forCellWithReuseIdentifier:@"collectionCell"];
collectionViewFlow.itemSize = CGSizeMake(, );
collectionViewFlow.sectionInset = UIEdgeInsetsMake(, , , );
collectionViewFlow.scrollDirection = UICollectionViewScrollDirectionVertical;
[_homeScrollView addSubview:collectView];
}
//datasource,delegate
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
return ;
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
CSHomeCollectionViewCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"collectionCell" forIndexPath:indexPath];
cell.topImage.image = [UIImage imageNamed:@"cludy_bg"];
return cell;
}
从而来实现对应的方法,其中自定义的cell类
-(instancetype)initWithFrame:(CGRect)frame
{
self =[super initWithFrame:frame];
if (self) {
self.backgroundColor = [UIColor grayColor];
self.topImage = [[UIImageView alloc]initWithFrame:CGRectMake(, , MYSIZE.width-, MYSIZE.height*0.6)];
[self addSubview:_topImage]; self.designer = [[UILabel alloc]initWithFrame:CGRectMake(, CGRectGetHeight(self.topImage.frame), CGRectGetWidth(self.frame), )]; self.designer.text = @"hello";
[self addSubview:_designer]; // self.goodBtn = [UIButton alloc]initWithFrame:CGRectMake(0, <#CGFloat y#>, <#CGFloat width#>, <#CGFloat height#>) }
return self;
}
当定义的时候,自动调用initwithframe函数来初始化
collectionview使用的更多相关文章
- 用collectionview实现瀑布流-转(后面附demo,供参考)
算法总体思路 先说一下总体上的思路.既然图片的大小.位置各不一样,我们很自然地会想到需要算出每个item的frame,然后把这些frame赋值给当前item的UICollectionViewLayou ...
- CollectionView水平和竖直瀑布流的实现
最近在项目中需要实现一个水平的瀑布流(即每个Cell的高度是固定的,但是长度是不固定的),因为需要重写系统 UICollectionViewLayout中的一些方法通过计算去实现手动布局,所以本着代码 ...
- tableViewCell嵌套collectionView,动态高度
方法有很多,有通过内容高度,经过代理回调,刷新的,甚至还有计算cell个数,然后根据cell大小计算的,这里推荐iOS 8新特性,通过AutoLayout,利用内容将cell撑起来; 关键代码: vi ...
- iOS开发之窥探UICollectionViewController(二) --详解CollectionView各种回调
UICollectionView的布局是可以自己定义的,在这篇博客中先在上篇博客的基础上进行扩充,我们先使用UICollectionViewFlowLayout,然后好好的介绍一下UICollecti ...
- WPF CollectionViewSource CollectionView
CollectionView 通俗讲就是可以对你绑定的集合可以进行 分组,排序 等功能 CollectionViewSource 根据字面意思是xxx的数据源 详细的介绍还是看 http://www ...
- ios中自定义tableView,CollectionView的cell什么时候用nib加载,什么时候用标识重用
做了一段时间的iOS,在菜鸟的路上还有很长的路要走,把遇到的问题记下来,好记性不如烂笔头. 在项目开发中大家经常会用到tableView和collectionView两个控件,然而在cell的自定义上 ...
- collectionview cell吸顶效果
p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px "Hiragino Sans GB"; color: #cf8724 } ...
- collectionView
// /* UICollectionView 类是iOS6 新引进的API,用于展示集合视图, 布局更加灵活,可实现多列布局,用法类似于UITableView类. - 更新视图: [collectio ...
- ios - 纯代码创建collectionView
开始考虑好一点点时间,因为一般的都是用xib,或者storyboard来写的.这次用纯代码...废话较多请看 首先把storyboard干掉,工程里面的main干掉 由于干掉了storyboard则启 ...
随机推荐
- selenium win7+selenium2.0+python环境搭建
- UWP/Win10新特性系列—Drag&Drop 拖动打开文件
在Win10 App开发中,微软新增了系统PC文件与UWP 之间的文件拖拽行为,它支持将系统磁盘上的文件以拖拽的形式拖入App中并处理,在前不久的微软build 2015开发者大会上微软展示的UWP版 ...
- CSS样式-文字超出宽部分用省略号代替
.name {text-overflow: ellipsis;white-space: nowrap;overflow: hidden;display:block;width:120px; }
- mysql 信息查询
show tables information 除了查询数据,管理数据之外,还有其他方面的信息方便和约束着 -- show information about characterset,查询mys ...
- [转]: 两分钟彻底让你明白Android Activity生命周期(图文)!
转自:http://blog.csdn.net/android_tutor/article/details/5772285 大家好,今天给大家详解一下Android中Activity的生命周期,我在前 ...
- iOS中常用的设计模式
常用的设计模式(一)代理模式应用场景:当一个类的某些功能需要由别的类来实现,但是又不确定具体会是哪个类实现.优势:解耦合敏捷原则:开放-封闭原则实例:tableview的 数据源delegate,通过 ...
- iOS复选框
这种按钮iOS没有原生效果. 可以靠按钮的不同点击状态来实现这个效果. 代码如下: _workBtn = [UIButton buttonWithType:UIButtonTypeCustom]; [ ...
- CGRectInset & CGRectOffset
1.CGRectInset CGRect CGRectInset ( CGRect rect, CGFloat dx, CGFloat dy);以原rect为中心,再参考dx,dy,进行缩 ...
- 数位DP之奥义
恩是的没错数位DP的奥义就是一个简练的dfs模板 int dfs(int position, int condition, bool boundary) { ) return (condition ? ...
- 改进:js修改iOS微信浏览器的title
问题简介 前端入门没多久,可能连入门也不算,最近网上流行各自书籍改名,什么<前端开发,从入门到放弃>,<Android开发,从入门到改行>之类的,程序员真是个爱自嘲的群体,但我 ...