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 ...
随机推荐
- [ubuntu] ubuntu13.04安装rabbitcvs管理svn
加入源 sudo add-apt-repository ppa:rabbitvcs/ppa 更新 sudo apt-get update 安装软件 sudo apt-get install rabbi ...
- js获取单选框radio的值
遇到一个js获取radio值的问题,原来根据frm.type.value取到的值在ie下是空值 解决办法:type为每个radio的值 var chkObjs=document.getElements ...
- 0-9、a-z、A-Z 随机数
MXS&Vincene ─╄OvЁ &0000006 ─╄OvЁ MXS&Vincene MXS&Vincene ─╄OvЁ:今天很残酷,明天更残酷,后天很美好 ...
- IT职业选择与定位
(一) 位置有很多,最适合你的是哪个? 有的人在电子技术的层面工作,开发出性能强劲的芯片和硬件产品:有的人在别人开发的芯片和硬件上开发各种操作系统和驱动程序:有的人在各种操作系统或设备 ...
- STM32模拟I2C
之前为了测试, 拿最小板做了一个I2C的主发跟主读, 一开始当然是尝试用硬件I2C, 结果弄了很久, 时间紧迫, 只好用了模拟, 结果发现, 哎, 真特么挺好用的, 现在1片儿顶过去5片儿. 硬件I2 ...
- 理解逐次逼近寄存器型ADC:与其它类型ADC的架构对比【转】
转自:http://bbs.dzsc.com/space/viewspacepost.aspx?postid=86760 摘要:逐次逼近寄存器型(SAR)模数转换器(ADC)占据着大部分的中等至高分辨 ...
- js 如何生成唯一且不可预测的 ID
通常数据库可以生成唯一的 ID,最多的就是数字序列,也有像 MongoDB 这样产生组合序列的,不过这种形式的 ID 由于是序列,是可以预测的.如果想得到不可预测且唯一的 ID,方法还是有的. 下面主 ...
- linux ll 命令各列的含义
linux ll 命令各列的含义:
- vmdk虚拟机转换为OVF模板,导入esxi
VMware WorkStation安装目录下,有一个OVFTool文件夹,例如我电脑上的路径为:D:\VMware\VMware\OVFTool.通过CMD进入到命令行模式,更改到该目录下,运行如下 ...
- Android TextView中 字体加粗方法
textView.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));//加粗 textView.getPaint().setFakeBoldT ...