collectionView的案例
- #import "ViewController.h"
- #import "CollectionViewCell.h"
- @interface ViewController ()<UICollectionViewDataSource,UICollectionViewDelegate,UICollectionViewDelegateFlowLayout>
- @property (weak, nonatomic) IBOutlet UICollectionView *collectionCell;
- @end
- @implementation ViewController
- - (void)viewDidLoad
- {
- [super viewDidLoad];
- self.collectionCell.backgroundColor = [UIColor greenColor];
- self.collectionCell.dataSource = self;
- self.collectionCell.delegate = self;
- }
- #pragma mark -- UICollectionViewDataSource
- //设置collectionCell的个数
- -(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
- {
- return 9;
- }
- //定义展示的Section的个数
- -(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
- {
- return 1;
- }
- //每个UICollectionView展示的内容
- -(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
- {
- //使用collectionCell进行注册,通过xib文件加载视图
- [self.collectionCell registerNib:[UINib nibWithNibName:@"myCell" bundle:nil]
- forCellWithReuseIdentifier:@"mycell"];
- CollectionViewCell *cell = (CollectionViewCell *)[collectionView dequeueReusableCellWithReuseIdentifier:@"mycell" forIndexPath:indexPath];
- //图片名称
- NSString *imageToLoad = [NSString stringWithFormat:@"%ld.jpg", indexPath.row];
- //加载图片
- cell.iamgeView.image = [UIImage imageNamed:imageToLoad];
- //设置label文字
- cell.labeiInfo.text = [NSString stringWithFormat:@"image%ld",indexPath.row];
- return cell;
- }
- //设置每个各自的大小
- -(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
- {
- return CGSizeMake(170, 170);
- }
- //定义每个UICollectionView 的 margin
- -(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
- {
- return UIEdgeInsetsMake(5, 5, 5, 5);
- }
- //UICollectionView被选中时调用的方法
- -(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
- {
- UICollectionViewCell * cell = (UICollectionViewCell *)[collectionView cellForItemAtIndexPath:indexPath];
- cell.backgroundColor = [UIColor whiteColor];
- }
- //返回这个UICollectionView是否可以被选择
- -(BOOL)collectionView:(UICollectionView *)collectionView shouldSelectItemAtIndexPath:(NSIndexPath *)indexPath
- {
- return YES;
- }
- //隐藏状态栏
- -(BOOL)prefersStatusBarHidden
- {
- return YES;
- }
- @end
程序运行结果:
collectionView的案例的更多相关文章
- Dynamic支持CollectionView布局 、 MotionEffects特效 、 BlurImage效果 、 TextKit
1 使用UIDynamicAnimator对集合视图进行布局 1.1 问题 UIKit Dynamic动力模型一个非常有趣的用途就是影响集合视图的布局,可以给集合视图的布局添加各种动力行为,使其产生丰 ...
- 数据库优化案例——————某市中心医院HIS系统
记得在自己学习数据库知识的时候特别喜欢看案例,因为优化的手段是容易掌握的,但是整体的优化思想是很难学会的.这也是为什么自己特别喜欢看案例,今天也开始分享自己做的优化案例. 最近一直很忙,博客产出也少的 ...
- SQL Server内存遭遇操作系统进程压榨案例
场景: 最近一台DB服务器偶尔出现CPU报警,我的邮件报警阈(请读yù)值设置的是15%,开始时没当回事,以为是有什么统计类的查询,后来越来越频繁. 探索: 我决定来查一下,究竟是什么在作怪,我排查的 ...
- solr_架构案例【京东站内搜索】(附程序源代码)
注意事项:首先要保证部署solr服务的Tomcat容器和检索solr服务中数据的Tomcat容器,它们的端口号不能发生冲突,否则web程序是不可能运行起来的. 一:solr服务的端口号.我这里的sol ...
- Yeoman 官网教学案例:使用 Yeoman 构建 WebApp
STEP 1:设置开发环境 与yeoman的所有交互都是通过命令行.Mac系统使用terminal.app,Linux系统使用shell,windows系统可以使用cmder/PowerShell/c ...
- 了不起的 nodejs-TwitterWeb 案例 bug 解决
了不起的nodejs算是一本不错的入门书,不过书中个别案例存在bug,按照书中源码无法做出和书中相同效果,原本兴奋的心情掺杂着些许失落. 现在我们看一下第七章HTTP,一个Twitter Web客户端 ...
- 一个表缺失索引发的CPU资源瓶颈案例
背景 近几日,公司的应用团队反应业务系统突然变慢了,之前是一直比较正常.后与业务部门沟通了解详情,得知最近生意比较好,同时也在做大的促销活动,使得业务数据处理的量出现较大的增长,最终系统在处理时出现瓶 ...
- 【Machine Learning】决策树案例:基于python的商品购买能力预测系统
决策树在商品购买能力预测案例中的算法实现 作者:白宁超 2016年12月24日22:05:42 摘要:随着机器学习和深度学习的热潮,各种图书层出不穷.然而多数是基础理论知识介绍,缺乏实现的深入理解.本 ...
- Redis简单案例(二) 网站最近的访问用户
我们有时会在网站中看到最后的访问用户.最近的活跃用户等等诸如此类的一些信息.本文就以最后的访问用户为例, 用Redis来实现这个小功能.在这之前,我们可以先简单了解一下在oracle.sqlserve ...
随机推荐
- SUSE10 SP4源码升级Python到2.6.6
1.安装依赖包(CentOS可采用yum) zypper in gcc gcc-c++ openssl-devel-32bit openssl-devel readline-devel readlin ...
- Error:“const char*”类型的实参与“wchar_t”类型的形参不兼容
MainApp\RPolarView.cpp(1571): error C2664: “ATL::CStringT<BaseType,StringTraits>::ReverseFind” ...
- iOS 实现从后台切换到前台-复制分享宝贝内容,打开淘宝APP,自动弹出宝贝提示信息
- (void)applicationDidBecomeActive:(UIApplication *)application { NSLog(@"\n ===> 程序重新激活 !&q ...
- 谈抽象1——无脑copy等于自杀
近期被外派帮助国内某公司做政府某部门OA系统.听说他们那有个成熟的java框架,使用了非常长时间,抱着学习的态度,我进入这个公司.当我熟悉了一周后,留下了非常多疑问,而这些疑问,也诱发了这次关于&qu ...
- influxDB 变换类函数
1.DERIVATIVE()函数 作用:返回一个字段在一个series中的变化率. InfluxDB会计算按照时间进行排序的字段值之间的差异,并将这些结果转化为单位变化率.其中,单位可以指定,默认为1 ...
- iOS 多线程之 GCD 的基本使用
什么是GCD 全称Grand Central Dispatch 中暑调度器 纯C语言 提供了很多强大的函数 GCD 的优势 GCD是苹果公司为多核的并行运算提出的解决方案 GCD会自动利用更多的CPU ...
- ArcGIS for window mobile 数据打开
前言 环境信息:ArcGIS for windows mobile 10.1.1,ArcGIS runtime sdk for windows mobile 10.1.1 一.MapCache的打开 ...
- Webstorm如何设置背景色为护眼色(豆绿色)
本文主要讲webstorm如何设置背景色. 1.打开idea Settings 选择 Editor——Color Scheme——General 注意:如果是Mac,在webstorm界面按键:“co ...
- 如何使用 stl 进行排列组合?
#include <iostream> #include <vector> #include <algorithm> //从 indexs 集合中选择 num 个元 ...
- HDU 4193 Non-negative Partial Sums(单调队列)
题目大意: 给定一个长度为n的循环序列.从n个不同位置開始,问有几个位置使得一下情况成立:全部前缀的和都大等于0(n <=1000000). 下午的训练赛.之前没学过单调队列所以用的线段树 ...