UICollectionView 使用
/**
初始化UICollectionView
*/
UICollectionViewFlowLayout *flowLayout=[[UICollectionViewFlowLayout alloc] init];
[flowLayout setScrollDirection:UICollectionViewScrollDirectionHorizontal];
flowLayout.minimumLineSpacing = ;
flowLayout.minimumInteritemSpacing=; _deviceCollectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(, , kScreenWidth, kHeightPro()*) collectionViewLayout:flowLayout]; //设置代理
_deviceCollectionView.delegate = self;
_deviceCollectionView.dataSource = self;
[self.view addSubview:_deviceCollectionView];
[_deviceCollectionView setBackgroundColor:RGBColor(0xf3, 0xf6, 0xf8)]; // Register cell classes
[_deviceCollectionView registerClass:[AnbotDeviceCollectionViewCell class] forCellWithReuseIdentifier:reuseIdentifier];
#pragma mark -- <UICollectionViewDataSource> - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
return ;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return ;
} - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { AnbotDeviceCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:reuseIdentifier forIndexPath:indexPath];
[cell sizeToFit];
if (!cell) {
NSLog(@"无法创建CollectionViewCell时打印,自定义的cell就不可能进来了。");
}
[self configureCell:cell atIndexPath:indexPath]; return cell;
} - (void)configureCell:(AnbotDeviceCollectionViewCell *)cell atIndexPath:(NSIndexPath*)indexPath
{ int index = indexPath.row *+ indexPath.section;
cell.section = indexPath.section;
[cell setEnableImage:UIResourceBundleSubDevice(imageOpenArr[index])];
[cell setDisableImage:UIResourceBundleSubDevice(imageCloseArr[index])];
// [cell setImage:UIResourceBundleSubDevice(imageOpenArr[index])]; [cell setNameText:titleArr[index]]; [cell setDeviceNum:[devCountArr[index]integerValue]];
[cell setNeedsUpdateConstraints];
[cell updateConstraintsIfNeeded];
} -(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
return UIEdgeInsetsMake(, , , );
} - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{ return CGSizeMake(kScreenWidth/, collectionView.frame.size.height/);
} - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
// NSLog(@"cell #%d was selected %d", indexPath.row,indexPath.section); int index = indexPath.row *+ indexPath.section;
if ([devCountArr[index] integerValue]==) {
return;
} NSPredicate *predicate = [NSPredicate predicateWithFormat:@" deviceType == %d ",index];
NSMutableArray *tempArray = [NSMutableArray arrayWithArray:deviceArr];
[tempArray filterUsingPredicate:predicate];
AnbotSingleDeviceManagerVC *singleVC = [[AnbotSingleDeviceManagerVC alloc]init];
singleVC.index = index; //indexPath.row *2+ indexPath.section;
singleVC.singleDevArr = tempArray;
// singleVC.devInfo = deviceArr[index];
[self.navigationController pushViewController:singleVC animated:YES]; }
UICollectionView 使用的更多相关文章
- 【iOS】Xcode8+Swift3 纯代码模式实现 UICollectionView
开发环境 macOS Sierra 10.12.Xcode 8.0,如下图所示: 总体思路 1.建立空白的storyboard用于呈现列表 2.实现自定义单个单元格(继承自:UICollectionV ...
- 使用UICollectionView实现首页的滚动效果
实现类似这样的效果,可以滚动大概有两种实现方案 1. 使用scrollview来实现 2. 使用UICollectionView来实现 第一种比较简单,而且相对于性能来说不太好,于是我们使用第二种方案 ...
- 用NSCalendar和UICollectionView自定义日历,并实现签到显示
前一段时间因为工作需要实现了一个可以签到的日历,来记录一下实现的思路 效果如图: 这里的基本需求是: 1,显示用户某个月的签到情况,已经签到的日子打个圈,没有签到且在某个时间范围内的可以签到,其他 ...
- UICollectionView布局cell的三种方式
UICollectionViewFlowLayout里面: // 方法一 - (void)prepareLayout{} // 方法二 - (nullable NSArray<__kindof ...
- 【Swift】iOS UICollectionView 计算 Cell 大小的陷阱
前言 API 不熟悉导致的问题,想当然的去理解果然会出问题,这里记录一下 UICollectionView 使用问题. 声明 欢迎转载,但请保留文章原始出处:) 博客园:http://www.cn ...
- UICollectionLayout布局 —— UIKit之学习UICollectionView记录二《流水布局》
重点知识 一. 加载collectionView注意事项 1.创建collectionView,有两种方式 :一种是xib和一种是纯代码:设置代理和数据源,注册cell,配置流水布局的属性,如上.下. ...
- UICollectionView中使用 UICollectionViewFlowLayout进行布局(模仿苹果相册)
现在都知道,在初始化UICollectionView的时候,必须要传入一Layout对象,进行布局管理.这也是collectionview和tableview的明显区别,通过collectionvie ...
- UI第十九节——UICollectionView
UICollectionView其实就是UITableView的升级版,在布局方面比UITableView更出色.下面,先看代码吧 #import "RootViewController.h ...
- iOS6新特征:UICollectionView介绍
http://blog.csdn.net/eqera/article/details/8134986 1.1. Collection View 全家福: UICollectionView, UITab ...
- 【iOS】UITabView/UICollectionView 全选问题
UITabView/UICollectionView 全选问题 SkySeraph July. 30th 2016 Email:skyseraph00@163.com 更多精彩请直接访问SkySera ...
随机推荐
- 夺命雷公狗---DEDECMS----16dedecms取出首页今日更新
我们这次就要来取出我们的电影和电视剧以及综艺节目: 我们首先在我们受页面的模版文件中获取电影和电视剧的标签: 我们发现这里有一大堆,我只留一个即可: 然后我们到后台更新下首页的模版,看下是否只有一个模 ...
- Android小案例——简单图片浏览器
今天上午休息看Android书,里面有个变化图片的示例引起了我的兴趣. 示例需求: 有N张图片,循环显示图片的内容.如果需求让我写我会使用一个变量count来保存显示图片数据的索引,图片显示时做个判断 ...
- 显示刚刚添加的最后一条数据,access,选择语句,select
显示刚刚添加的最后一条数据,access,选择语句,select select top 1 * from s1 order by id desc
- Sinatra+SQLite3+DataMapper - 十分完整的tutorial - “Superdo”
原文地址:https://ididitmyway.herokuapp.com/past/2010/3/30/superdo_a_sinatra_and_datamapper_to_do_list/ 这 ...
- js获取单选框radio的值
遇到一个js获取radio值的问题,原来根据frm.type.value取到的值在ie下是空值 解决办法:type为每个radio的值 var chkObjs=document.getElements ...
- php里session的用法
PHP中的session默认情况下是使用客户端的Cookie.当客户端的Cookie被禁用时,会自动通过Query_String来传递. Php处理会话的函数一共有11个,我们详细介绍一下将要用到几个 ...
- 七、Java基础---------JDK安装与配置
配置环境变量名词说明 path:通过path系统去寻找可执行的java文件. JAVA_HOME:JDK的安装目录 classpath:加载目录 为什么需要配置path,什么时候需要classpath ...
- Subversion简明手册--使用hook svn
使用 hook ,为了方便管理员 控制提交的过程 Subversion 提供了 hook 机制.当特定的 事件发生时,相应的 hook 会被调用, hook 其实就相当于特定 事件的处理函数.每个 h ...
- java笔试题整理
exit()是system类的方法,如system.exit(); 如果某个方法是静态的,它的行为就不具有多态性. 类后面没有括号,方法必须要有返回值.如果没有返回值,要写void 构造函数不具有多态 ...
- eclipse 利用已有c++代码建工程,并编译执行
如果你想建一个带Makefile的c++ 工程 1. 新建一个C++空工程,工程类型是makefile project,选择Linux GCC: 2. 将源码连同makefile文件一同作为一个文件系 ...