class testViewController:BaseViewController,UICollectionViewDataSource, UICollectionViewDelegate , UICollectionViewDelegateFlowLayout{
lazy var myCollectionView:UICollectionView = {
let layout = UICollectionViewFlowLayout()
layout.minimumLineSpacing = 1.5 //上下间隔
layout.minimumInteritemSpacing = 1 //左右间隔
let collectionView = UICollectionView(frame: CGRectZero, collectionViewLayout:layout)
collectionView.backgroundColor = UIColor.whiteColor()
return collectionView
}() override func viewDidLoad() {
super.viewDidLoad()
//加载页面元素
self.addSubView()
self.makeConstraints()
self.myCollectionView.reloadData()
} func addSubView(){
self.view.backgroundColor = UIColor(rgba: "#F1F1F1")
self.myCollectionView.delegate = self
self.myCollectionView.dataSource = self //注册header
self.myCollectionView.registerClass(UICollectionReusableView.self, forSupplementaryViewOfKind: UICollectionElementKindSectionHeader, withReuseIdentifier: "TESTHeader") self.myCollectionView.registerClass(UICollectionViewCell.self, forCellWithReuseIdentifier: "TESTCell")
self.view.addSubview(myCollectionView)
} //增加约束
func makeConstraints(){
//Add Constraints
myCollectionView.snp_makeConstraints{make in
make.top.bottom.left.right.equalTo(self.view)
}
} //MARK: - CollectionView 代理方法
func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
//分栏数量
return 10
} func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
//每个分栏中Cell的个数
return 2
} func collectionView(collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, atIndexPath indexPath: NSIndexPath) -> UICollectionReusableView {
var reuseView:UICollectionReusableView
reuseView = collectionView.dequeueReusableSupplementaryViewOfKind(UICollectionElementKindSectionHeader, withReuseIdentifier: "TESTHeader", forIndexPath: indexPath)
reuseView.backgroundColor = UIColor.blackColor()
return reuseView
} ///cell内容
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
//返回复用的cell
var cell = collectionView.dequeueReusableCellWithReuseIdentifier("TESTCell", forIndexPath: indexPath)
if indexPath.row % 2 == 0 {
cell.backgroundColor = UIColor.redColor()
}else{
cell.backgroundColor = UIColor.blueColor()
}
return cell
} func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize {
//返回每个cell的大小
return CGSize(width: KMainScreenWidth, height:150)
} func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForFooterInSection section: Int) -> CGSize {
var h:CGFloat = 15
return CGSizeMake(KMainScreenWidth,h)
} func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForHeaderInSection section: Int) -> CGSize {
//返回sectionview的大小
var h:CGFloat = 50
return CGSizeMake(KMainScreenWidth,h)
} func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAtIndex section: Int) -> UIEdgeInsets{
return UIEdgeInsets(top:0, left: 0, bottom:5, right: 0)
} func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
//Cell点击事件
}
}

UICollectionView swift2模版的更多相关文章

  1. [IOS UICollectionView模版]

    创建CollectionCell模版: 1.新建类CollectionCell继承自UICollectionViewCell 2.新建Xib,命名为CollectionCell.xib a.选中Col ...

  2. 【iOS】UICollectionView自己定义Layout之蜂窝布局

    网上的UICollectionView的Layout布局,其cell的形状多为矩形和圆形. 本篇博文将正六边形作为cell的基本形状,为您展现独特的蜂窝布局效果及实现源代码. 帮助您让自己的App脱颖 ...

  3. 【iOS】Xcode8+Swift3 纯代码模式实现 UICollectionView

    开发环境 macOS Sierra 10.12.Xcode 8.0,如下图所示: 总体思路 1.建立空白的storyboard用于呈现列表 2.实现自定义单个单元格(继承自:UICollectionV ...

  4. 创建ABPboilerplate模版项目

    本文是根据角落的白板报的<通过ABPboilerplate模版创建项目>一文的学习总结,感谢原文作者角落的白板报. 1 准备 开发环境: Visual Studio 2015 update ...

  5. 使用boilerplate模版创建解决方案

    返回总目录<一步一步使用ABP框架搭建正式项目系列教程> 话不多说,让我们开始干吧!对于还没有接触ABP框架或者接触时间还不是很长的小伙伴来说,我建议还是使用官方建议的做法,那就是到ABP ...

  6. ASP.NET MVC5+EF6+EasyUI 后台管理系统(29)-T4模版

    系列目录 本节不再适合本系统,在58,59节已经重构.请超过本节 这讲适合所有的MVC程序 很荣幸,我们的系统有了体验的地址了.演示地址 之前我们发布了一个简单的代码生成器,其原理就是读取数据库的表结 ...

  7. 构建自己的PHP框架--构建模版引擎(1)

    前段时间太忙,导致好久都没有更新博客了,今天抽出点时间来写一篇. 其实这个系列的博客很久没有更新了,之前想好好规划一下,再继续写,然后就放下了,今天再捡起来继续更新. 今天我们来说一下,如何构建自己的 ...

  8. 使用UICollectionView实现首页的滚动效果

    实现类似这样的效果,可以滚动大概有两种实现方案 1. 使用scrollview来实现 2. 使用UICollectionView来实现 第一种比较简单,而且相对于性能来说不太好,于是我们使用第二种方案 ...

  9. asp.net读取模版并写入文本文件

    本文要介绍的是ASP.NET怎样读写文本文件,但更重要的是实现的过程.使用的工具是Visual Studio 2015 ,.NET版本是4.6.1 .一共建立的2个项目,HoverTreePanel和 ...

随机推荐

  1. 柯朗数(Courant number)研究

    在数值计算过程中,对于计算结果的准确性和效率有很高的要求,但是这两者之间往往互相矛盾:而使用柯朗数可用于平衡两者. 1.柯朗数的定义: C = sqrt(gh)*t/s 其中,t是时间步长,s是网格在 ...

  2. Kafka深入理解-3:Kafka如何删除数据(日志)文件

    Kafka作为消息中间件,数据需要按照一定的规则删除,否则数据量太大会把集群存储空间占满. 参考:apache Kafka是如何实现删除数据文件(日志)的 Kafka删除数据有两种方式 按照时间,超过 ...

  3. cookie 和session 的区别

    假如我填好了淘宝的用户名密码,点击登录,浏览器客户端像服务器端发送请求,这时服务器端看这个用户是第一次登陆,session会让客户端这个浏览器生成个cookie,并给cookie一个session i ...

  4. [delphi]极域学生端解除键盘鼠标锁定退出全屏广播-强制窗口化-源代码

    v2.0  2015-07-11 更新了V2.0 版本 发布在吾爱破解论坛 欢迎下载使用 http://www.52pojie.cn/thread-382769-1-1.html ---------- ...

  5. UE3 ExampleGame Android版无法运行解决方案

    首先将 UE3\UnrealEngine3\UDKGame\Build\Android 文件夹 拷贝到 ExampleGame\Build下面.里面有相应的android 配置文件.xml 若果此时 ...

  6. js 和 jq 控制 checkbox

    判断checkbox是否选中  1. $("#id").attr("checked") 在jquery 1.6前(含1.6),返回值是boolean类型的tru ...

  7. jquery 原理

    /* * my-jquery-1.0 *//* * 网上也有很多实现的版本,不过这是我在我自己的理解下写的,加上注释,希望可以解释清楚.*//* * 整个jquery包含在一个匿名函数中,专业点叫闭包 ...

  8. spring 异常记录

    1.异常: java.lang.IllegalArgumentException: No converter found for return value of type: class java.ut ...

  9. 用node搭建静态文件服务器

    占个坑,写个node静态文件服务器

  10. 【活动】监控宝惹火Docker监控,开放试用中

    要说这两年最火爆的技术有哪些,Docker绝对是其中之一. 有人说,Docker缺少必要的运维监控工具,实践起来有难度. 幸福来的太快了. 云智慧旗下产品监控宝又惹火了,推出重量级新功能——Docke ...