UICollectionViewController xcode6.1 自定义Cell
虽然这个早已不是新东西了,但是之前项目中一直没有机会用,只知道跟tableView原理相同。
弄了个自定义UICollectionViewCell的小DEMO:
(1)在storyboard中拖拽一个UICollectionViewController:
(2)新建RootCollectionViewController继承自UICollectionViewController
- #import "RootCollectionViewController.h"
- #import "RootCollectionViewCell.h"
- @interface RootCollectionViewController ()
- @end
- @implementation RootCollectionViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
- self.clearsSelectionOnViewWillAppear = NO;
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- }
- #pragma mark <UICollectionViewDataSource>
- - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
- return 1;
- }
- - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
- return 20;
- }
- - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
- static NSString * CellIdentifier = @"GradientCell";
- RootCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:CellIdentifier forIndexPath:indexPath];
- cell.backgroundColor = [UIColor colorWithRed:((110 * indexPath.row) / 255.0) green:((220 * indexPath.row)/255.0) blue:((330 * indexPath.row)/255.0) alpha:1.0f];
- [cell.lab setText:@"xxxx"];
- [cell.frontView setBackgroundColor:[UIColor redColor]];
- return cell;
- }
- #pragma mark <UICollectionViewDelegate>
- @end
(3)新建RootCollectionViewCell继承自UICollectionViewCell,头文件如下,自定义两个控件
- #import <UIKit/UIKit.h>
- @interface RootCollectionViewCell : UICollectionViewCell
- @property(nonatomic,weak)IBOutlet UILabel *lab;
- @property(nonatomic,weak)IBOutlet UIView *frontView;
- @end
(4)storyboard操作:
点击CollectionViewController,设置Class:
点击CollectionCell设置Class:
拖动一个View和lab到CollectionView上,设置约束为固定宽高上下居中:
点击左侧的CollectionCell,,将IBOutlet,连接到lab和frontView上:
设置大小及边距,当然了,xcode6以后,也可以根据不同的屏幕设置相应SizeClass下的边距:
(5)运行效果:
UICollectionViewController xcode6.1 自定义Cell的更多相关文章
- iOS 中使用 XIB 自定义cell 的两种方法 以及 编译出现常见 的错误 ++++(xcode6.0之后)
一. 注册cell 1.创建自定义cell并勾选 xib :(勾选xib就会自动生成与cell文件关联的xib) 2.在 tableViewController里注册自定义Cell (或者遵守tabl ...
- iOS 中使用 XIB 自定义cell的两种方法以及编译出现常见 的错误 (xcode6.0之后)
一. 注册cell 1.创建自定义cell并勾选 xib :(勾选xib就会自动生成与cell文件关联的xib) 2.在 tableViewController里注册自定义Cell (或者遵守tabl ...
- 自定义cell自适应高度
UITableView在许多App种被大量的应用着,呈现出现的效果也是多种多样的,不能局限于系统的一种样式,所以需要自定义cell 自定义cell呈现的内容也是多种多样的,内容有多有少,所以需要一种能 ...
- 自定义cell(xib)中button点击事件不能响应的情况
遇到这种问题真的好尴尬,之前从来没有遇到过,以为手到擒来,未曾料到还会遇到问题! 好多年没有找到尴尬的感觉,现在找到了,真的很尴尬 ! *o* 1.首先使用场景: 原本没打算用xib,后来为了快速, ...
- ios中自定义cell 设置cell的分组结构
ios系统默认的cell并不能满足我们的需求 这个时候就需要自定义我们的cell 自定义cell为分组的时候 需要设置分组样式 以下是我常用分组的二种方法: 第一是 在自定义的UITableView ...
- iOS开发小技巧--纯代码自定义cell
纯代码自定义cell 自定义cell的步骤(每个cell的高度不一样,每个cell里面显示的内容也不一样) 1.新建一个继承自UITableViewCell的子类 2.在initWithStyle:方 ...
- 自定义cell的一些知识
1.要往cell里面添加一个自定义的子控件,都是添加到cell的contentView,不是添加到cell里面. 2.通过xib自定义cell * 添加tableView * 加载团购数据 * 新建x ...
- 给自定义cell赋值
搭建自定义cell-给自定义cell赋值的思路 1 主控制器 1.1导入头文件 #import "LHQInvestmentManagementCell.h" #import &q ...
- 自定义cell
思路就是创建模型,自定义cell,然后在主控制器中完成,首先要观察plist文件: Contact.h #import <Foundation/Foundation.h> @interfa ...
随机推荐
- 循环神经网络与LSTM网络
循环神经网络与LSTM网络 循环神经网络RNN 循环神经网络广泛地应用在序列数据上面,如自然语言,语音和其他的序列数据上.序列数据是有很强的次序关系,比如自然语言.通过深度学习关于序列数据的算法要比两 ...
- POJ-3352 Road Construction,tarjan缩点求边双连通!
Road Construction 本来不想做这个题,下午总结的时候发现自己花了一周的时间学连通图却连什么是边双连通不清楚,于是百度了一下相关内容,原来就是一个点到另一个至少有两条不同的路. 题意:给 ...
- BZOJ 4822 [Cqoi2017]老C的任务 ——树状数组
直接离散化之后用树状数组扫一遍. 把每一个询问拆成四个就可以做了. %Silvernebula 怒写KD-Tree #include <map> #include <cmath> ...
- c++ 多线程:线程句柄可以提前关闭,但是线程并没有关闭
很多程序在创建线程都这样写的:ThreadHandle = CreateThread(NULL,0,.....);CloseHandel(ThreadHandle );1,线程和线程句柄(Handle ...
- nmon性能分析工具(生成图表)
1. nmon性能结果生成报告工具下载地址: https://www.ibm.com/developerworks/community/wikis/home?lang=en#!/wiki/Power% ...
- PatentTips - Write Combining Buffer for Sequentially Addressed Partial Line Operations
SUMMARY OF THE INVENTION The present invention pertains to a write combining buffer for use in a mic ...
- idea 自定义工具栏
问题:在笔记本上面使用idea的时候,有时候,需要使用 Ctrl+Alt+左箭头 / Ctrl+Alt+右箭头 跳转到 上一次,查看代码的问题,然而存在快捷冲突的时候,很蛋疼.下面是解决办法. 效果 ...
- 什么是 Linux 发行版
什么是Linux的发行版 就Linux的本质来说,它只是操作系统的核心,负责控制硬件.管理文件系统.程序进程等,并不给用户提供各种工具和应用软件.所谓工欲善其事,被必先利其器,一套在优秀的操作系统核心 ...
- Ubuntu 16.04安装微信
微信没有出Linux的版本,但是可以通过以下方式解决: 1.使用网页版,除了没有公众号之后,一切都没问题,包括传文件等. 网页登录地址:https://wx.qq.com/ 2.使用第三方版本,只不过 ...
- error MIDL2311 解决方法
error MIDL2311 : statements outside library block are illegal in mktyplib compatability mode : [] 在编 ...