UICollectionView
2015-09-17 18:25
281 查看
UICollectionView 解释:选项框
1.拖拽一个Collection View控件到现有的View上
2.连接
Collection View连接到代码中,命名为mainCollectionView
3.包含代理
4.将代理设置为自己的
5.写下必选的代理函数
6.实现上述代理函数
事先要先自定义一个UICollectionViewCell的子类,类名假设CollectionViewCell,并包含同名xib
第一步:导入头文件并在ViewDidLoad内加入自定义CELL xib的注册
在行内容函数里
若没有写Cell的配置等东西,则显示你在TableViewCell.xlb中设置的东西
若要更多功能,则增加代理
1.拖拽一个Collection View控件到现有的View上
2.连接
Collection View连接到代码中,命名为mainCollectionView
3.包含代理
<UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>
4.将代理设置为自己的
[self.mainTableView setDelegate:self]; [self.mainTableView setDataSource:self];
5.写下必选的代理函数
//行数 - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { return 5; } //行内容 (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { } //定义每个UICollectionView 的大小 - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath { //通过调节每一行的大小及.xlb中Cell的大小来使Cell显示 return CGSizeMake(110, 90); }
6.实现上述代理函数
事先要先自定义一个UICollectionViewCell的子类,类名假设CollectionViewCell,并包含同名xib
第一步:导入头文件并在ViewDidLoad内加入自定义CELL xib的注册
[self.mainCollectionView registerNib:[UINib nibWithNibName:@"CollectionViewCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"mainIdentifier"];
在行内容函数里
static NSString *identifer = @"mainIdentifier"; CollectionViewCell *cell = (CollectionViewCell *)[collectionView dequeueReusableCellWithReuseIdentifier:identifer forIndexPath:indexPath]; //此处可以写cell的一些配置,内容,样式等 return cell;
若没有写Cell的配置等东西,则显示你在TableViewCell.xlb中设置的东西
若要更多功能,则增加代理
<UICollectionViewDelegate> //点击事件 - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath { NSLog(@"选中collectionViewCell :%ld", indexPath.row); }
相关文章推荐
- UI —— 计算器
- request.getParameter和request.getAttribute之间的区别
- (转)Git Gui for Windows的建库、克隆(clone)、上传(push)、下载(pull)、合并
- UIday1703:UITest17 代码练习
- django1.6 CSRF verification failed. Request aborted. 用出现表单提交
- html中获取select的value值和text值
- UIscrollView的几个属性contentSize contentOffset contentInset
- ios UIWindow 错误使用导致无法接收motionEnded(摇一摇)函数
- UIAlertController和UIImagePickerController的使用
- UIday1702:KVO 观察者设计模式 代码实现 常用
- easyui validatebox 验证类型
- UITextField/UITextView 选中时改变边框颜色及UITextView的Placeholder
- UIday1701:KVO观察者设计模式 代码
- String StringBuilder StringBuffer 对比 总结得非常好
- BIOS设置之UEFI/Legacy BIOS切换图文详解
- Arduino 看门狗使用
- UIday1604:get同步/异步 和 post同步/异步 编程实现
- ubuntu 14.04 build SURFGPU
- HDU 5437 Alisha’s Party (Priority_queue)2015 ACM/ICPC Asia Regional Changchun Online
- iPhone开发之显示指定格式的文本自动改变UIlabel高度的自定义分类—— 方便好用