原文链接:https://www.cnblogs.com/ludashi/p/4792480.html UICollectionView的布局是可以自己定义的,在这篇博客中先在上篇博客的基础上进行扩充...在UICollectionView中的Section中我们可以为其增加Header View和Footer View, 也就是官方文档上提到的Supplementary View(追加视图)。...(2) 因为我们是从xib文件中加载的UICollectionReusableView,所以需要在相应的UICollectionView上进行注册。...1.同一个Section中同一种Cell(通过同一个Cell重用标示符获取的对象)可以有不同的尺寸,下面的代码是给Cell定制尺寸。...NSLog(@"第%ld个Section上第%ld个Cell变为非高亮",indexPath.section ,indexPath.row); } } 4.Cell从非高亮变为高亮状态时回调用下面的方法
UICollectionView的布局是可以自己定义的,在这篇博客中先在上篇博客的基础上进行扩充,我们先使用UICollectionViewFlowLayout,然后好好的介绍一下UICollectionView...在UICollectionView中的Section中我们可以为其增加Header View和Footer View, 也就是官方文档上提到的Supplementary View(追加视图)。...(2) 因为我们是从xib文件中加载的UICollectionReusableView,所以需要在相应的UICollectionView上进行注册。...1.同一个Section中同一种Cell(通过同一个Cell重用标示符获取的对象)可以有不同的尺寸,下面的代码是给Cell定制尺寸。...20 21 } 4.Cell从非高亮变为高亮状态时回调用下面的方法,为了反映Cell的高亮状态,我们去改变一下Cell上ImageView的图片。
在了解UICollectionView的更多属性前,我们先来使用其进行一个最简单的流布局试试看,在controller的viewDidLoad中添加如下代码: //创建一个layout... UITableViewCell *)dequeueReusableCellWithIdentifier:(NSString *)identifier; //6.0后使用如下的方法直接从注册的cell类获取创建... NS_AVAILABLE_IOS(6_0); 我们可以分析:因为UICollectionView是iOS6.0之前的新类,因此这里统一了从复用池中获取cell的方法,没有再提供可以返回nil的方式,并且在...UICollectionView的回调代理中,只能使用从复用池中获取cell的方式进行cell的返回,其他方式会崩溃,例如: //这是正确的方法 -(UICollectionViewCell *)collectionView...则会在一列充满后,进行第二列的布局,这种方式也被称为流式布局 三、UICollectionView中的常用方法和属性 //通过一个布局策略初识化CollectionView - (instancetype
平常我在业务开发中,绝大部分情况都是使用的UITableView,而UICollectionView则是在极少情况下才会去使用,这就导致了我对UICollectionView略感陌生。...UITableView中的row,对应到UICollectionView中就是item,因为一行可以展示多个cell,使用row(行)不能准确地表达。...UITableView获取cell: 方式一:先注册,然后直接deque获取; 方式二:不用注册,dequeue+判断获取。...而UICollectionViewCell的获取,必须是先注册,然后通过dequeue方法获取。 系统默认给我们提供了一种layout——UICollectionViewFlowLayout。...UICollectionViewFlowLayout的设计理念就是,item现在一行中依次排列,一行满了之后就换一行接着排列剩余的Item。
中是否也能这样操作呢!...答案当然是肯定的,在 UICollectionView 控件中我们管这叫 Supplementary View, 翻译过来就是 "追加视图",那在 UICollectionView 中该怎么实现给每个...在接下来的内容中,你将会学到以下知识点: 1.如何在 UICollectionView 中创建 Decoration View2.自定义布局属性,计算 section 的背景图位置和大小3.实现 UICollectionView...中添加装饰视图。...(UIViewController)中呈现了,但是为了更进一步体现 UICollectionView 的强大,我还实现了一个功能,那就是使得书架里的书可以自由拖拽排序,这里就用到了另外一个知识点:手势
, didSelectItemAt indexPath: IndexPath) { } OC -(NSInteger)numberOfSectionsInCollectionView:(UICollectionView...{ // 获取当前显示的cell的下标 NSIndexPath *firstIndexPath = [[self.collectionView indexPathsForVisibleItems...,对应的class文件如下 class QuestionBookHeader: UICollectionReusableView { @IBOutlet weak var titleLabel:...QuestionBookHeader; if(indexPath.section == 0){ header.titleLabel.text = "我的分类" }else...indexPath: NSIndexPath) -> UICollectionViewCell { } func collectionView(collectionView: UICollectionView
在iOS10中,苹果为UICollectionViewCell引入了Pre-Fetching预加载机制用于提升它的性能。...collectionView:prefetchItemsAtIndexPaths 方法和collectionView:cancelPrefetchItemsAtIndexPaths 方法(可选) 3、将第1步中遵从协议的类设置为...UICollectionView 的 prefetchDataSource 属性 实现 一、创建UICollectionViewFlowLayout 自己写一个类继承自UICollectionViewFlowLayout...// 获取URL NSURL *imgURL = self.imgURLArray[indexPath.row]; //对应的URL的图片已经存在 if (self.imgs...效果演示.gif 写在后面的话 1、这个新特性仍然需要探究 2、遇到的一个坑:细心看的话可以发现我的字典是懒加载的,如果直接在viewDidLoad中初始化会在 weakSelf.imgs[currentURL
#####集合视图的作用 集合视图是为了增强网格视图开发而在IOS6中开放的集合视图API。 #####集合视图的组成 集合视图有4个重要的组成部分,分别为: 单元格:即视图中的一个单元格。...UICollectionView对应的控制器是UICollectionViewController类。...-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath...:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{ //获取当前要操作的Cell...*)collectionView didDeselectItemAtIndexPath:(NSIndexPath *)indexPath{ //获取当前要操作的Cell self.cell =
iOS流布局UICollectionView系列七——三维中的球型布局 一、引言 通过6篇的博客,从平面上最简单的规则摆放的布局,到不规则的瀑布流布局,再到平面中的圆环布局,我们突破了线性布局的局限...以下是前几篇博客地址: 1.初识与简单实用UICollectionView:http://my.oschina.net/u/2340880/blog/522613 2.UICollectionView的代理方法...scrollView.contentOffset = CGPointMake(scrollView.contentOffset.x-10*320,scrollView.contentOffset.y); } } 这里面的代码比较上一篇博客中的并没有什么大的改动...在我们的layout类中,将代码修改成如下: -(void)prepareLayout{ [super prepareLayout]; } //返回的滚动范围增加了对x轴的兼容 -(CGSize...]; //获取item的个数 int itemCounts = (int)[self.collectionView numberOfItemsInSection:0]; atti.center
效果图 接下来就是具体的实现。 1. 创建ViewController 命名为SHomeViewController。 2. 声明 UICollectionView。...设置代理,这里Xcode会提示有错误,暂时不用管,实现UICollectionView的代理方法后这个错误自然就没有了。...: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {...func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath)...从这个例子中我们发现Swift语言还是很简洁的。
配置 @IBOutlet weak var collectionView: UICollectionView!..., cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { let itemdata = colletcionData[indexPath.row..., didSelectItemAt indexPath: IndexPath) { //点击最后一张图 跳转到登录页面 if(indexPath.row == (self.colletcionData.count...var preferredStatusBarUpdateAnimation: UIStatusBarAnimation{ return UIStatusBarAnimation.slide } 获取...View的所有属性 主要用在修改一些组件的默认样式 这里用于获取UIPageControl的属性 修改原来的点为自己的图片 func runtime() { // 利用runtime 遍历出pageControl
前言 在iOS开发过程中,UICollectionView的使用仅次于UITableView的使用,而且UICollectionView的使用也很重要,需要很好的运用掌握相关知识点。...本篇博文就来讲解一下UICollectionView使用中,删除UICollectionViewCell的步骤方法,仅供参考。...使用场景:在UICollectionView的cell中,点击长按手势删除列表中的其中一个UICollectionViewCell的方法。具体实现步骤如下所示。...代理方法cellForItemAtIndexPath:中给UICollectionViewCell添加长按手势,添加长按手势的时候需要添加代理方法 UILongPressGestureRecognizer...:中获取被点击选中的NSIndexPath,给selectedIndexPath赋值 - (void)collectionView:(UICollectionView *)collectionView
(supplementaryViewType: SubscribeFooter.self, ofKind: UICollectionView.elementKindSectionFooter) 我换成原生的注册..., withReuseIdentifier: "SubscribeFooter") 一样的报错奇怪了 func collectionView(_ collectionView: UICollectionView..., viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView...(ofKind: UICollectionView.elementKindSectionHeader, for: indexPath, viewType: SubscribeHeader.self)..., for: indexPath, viewType: SubscribeFooter.self) return foot } } 在使用xib的时候,存在获取
iOS流布局UICollectionView系列二——UICollectionView的代理方法 一、引言 在上一篇博客中,介绍了最基本的UICollectionView的使用和其中我们常用的属性和方法...,也介绍了瀑布流布局的过程与思路,这篇博客是上一篇的补充,来讨论关于UICollectionView的代理方法的使用。...:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath; 取消选中某个Item时触发的方法...indexPath; 将要加载某个Item时调用的方法 - (void)collectionView:(UICollectionView *)collectionView willDisplayCell...; 长按菜单中可以触发一下类复制粘贴的方法,效果如下: ?
Swift中比较常见的控件UICollectionView 首先我们设置一个全局的UICollectionView和一个数据源 var colltionView : UICollectionView...,UICollectionViewDelegateFlowLayout 接下来我们要做的是override func viewDidLoad()方法中初始化一些必要的对象 override func...(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell...,这里的话我用的是Alamofire进行的网络请求,URL不方便透露 //获取数据 func getData(){ Alamofire.request(.GET, GoodsUrl).responseJSON...没错,我们的headview是不是还没整啊? 接下来呢,我们看下UICollectionView的headview该怎么设置 重点在这里!
自打 Apple 在 iOS6 中引入 UICollectionView 这个控件之后,越来越多的 iOS 开发者选择将它作为构建 UI 的首选,如此吸引人的原因在于它的可定制化程度非常的高,非常的灵活...说到布局 layout,大家在开发过程中与 UICollectionView 搭配使用最多的 应该就是 UICollectionViewFlowLayout 了,这是 UIKit 提供给开发者最基础的的网格布局...自定义布局 日常开发中,我们使用 UICollectionView 控件都会搭配一个默认的,提供一些基础的布局 UICollectionViewFlowLayout 来使用,但是当我们需要实现定制化程度比较高的界面时...查阅苹果的文档可以得知,UICollectionView 的布局是抽象类 UICollectionViewLayout 的子类,它定义了 UICollectionView 中每个 item 的布局属性叫做...工程中编译并运行,你就会看到 Cell 根据照片的高度正确放置并设置了大小: 好了, 利用 UICollectionView 控件与自定义布局实现瀑布流的内容到此就结束了,最后附上项目的源码地址
{ return 10; } //定义展示的Section的个数 -(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)...collectionView { return 2; } //每个UICollectionView展示的内容 -(UICollectionViewCell )collectionView:(UICollectionView...:indexPath]; //临时改变个颜色,看好,只是临时改变的。...如果要永久改变,可以先改数据源,然后在cellForItemAtIndexPath中控制。(和UITableView差不多吧!...(@"row=======%d",indexPath.row); NSLog(@"section===%d",indexPath.section); } //返回这个UICollectionView
前言 iOS UICollectionView 从右向左对齐(Aligning right to left on UICollectionView) 实现原理:采用setTransform对其进行水平翻转...在这里插入图片描述 I 、UICollectionView 从右向左对齐 本文按钮的视图结构 bottomV 内部采用UICollectionView进行布局。...设置阴影的圆角,//阴影的扩散范围,相当于blur radius,也是shadow的渐变距离,从外围开始,往里渐变shadowRadius距离 } /** NSMutableArray...上从右向左对齐(Aligning right to left on UICollectionView) //1、首先,在创建UICollectionView时,我对其进行了水平翻转:...]; QCTCollectionModel *model = self.models[indexPath.row]; cell.model =model; return cell
可以在VC中具体实现对应的方法: 定义每个Section的约束,具体作用是靠近左右边缘的距离,这里定义的上下距离约束会被其他协议覆盖掉 -(UIEdgeInsets)collectionView:(...NSLog(@"%f",(kDeviceHeight-88-49)/4.0); return CGSizeMake(152.5*NEWX,152.5*NEWX+58); } 每个section中不同的行之间的行间距...---- 也可以自定义一个 继承于 UICollectionViewFlowLayout 的约束,在自定义的约束中实现更强大的功能。比如这样的: ?...]; 最主要的是返回一个 item 的具体Frame attri.frame = CGRectMake(cellX, cellY, cellWidth, cellHeight); 实例中在自定义的方法中高度返回的是随机值...使用UICollectionView,UICollectionView在iOS6中第一次被介绍,它与UITableView有许多相似点,但它多了一个布局类,而实现瀑布流,就与这个布局类有关。
iOS流布局UICollectionView系列四——自定义FlowLayout进行瀑布流布局 一、引言 前几篇博客从UICollectionView的基础应用到设置UICollectionViewFlowLayout...这种布局无疑在app的应用中更加广泛,商品的展示,书架书目的展示,都会倾向于采用这样的布局方式,当然,通过自定义FlowLayout,我们也很容易实现。...,因此,collectionView在进行UI布局前,会通过这个类的对象获取相关的布局信息,FlowLayout类将这些布局信息全部存放在了一个数组中,数组中是UICollectionViewLayoutAttributes...:方法来获取这个布局配置数组。..., strong) NSIndexPath *indexPath; //获取item的类型 @property (nonatomic, readonly) UICollectionElementCategory
领取专属 10元无门槛券
手把手带您无忧上云