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. 阿里云slb和ucloud负载均衡ulb添加ssl证书将http服务https化的配置详解

    阿里云和ucloud服务器配置ssl证书将http服务https化的配置详解 项目背景: 苹果App于2017年1月1日将启用App Transport Security安全功能,即强制App通过HT ...

  2. 提升linux下tcp服务器并发连接数限制

    1.修改用户进程可打开文件数限制   在Linux平台上,无论编写客户端程序还是服务端程序,在进行高并发TCP连接处理时,最高的并发数量都要受到系统对用户单一进程同时可打开文件数量的限制(这是因为系统 ...

  3. OPTIMIZE TABLE 小解

    首先看一下语法:  OPTIMIZE [NO_WRITE_TO_BINLOG | LOCAL] TABLE tbl_name [, tbl_name] ... 我们知道mysql存储引擎里面的数据和索 ...

  4. 锋利的js之验证身份证号

    我们在做互联网网站时,注册个人资料时,经常要用到身份证号,我们需要对身份证进验证,不然别人随便输个号码就通过,让你感觉这个网站做得很shit. 身份证号是有规则的. 结构和形式 1.号码的结构  公民 ...

  5. 使用github参与开源项目

    github上有很多非常优秀的开源项目,作为开源项目的受益者,你否想过为开源项目贡献自己的代码?

  6. post请求接口

    /// <summary> /// post 调用接口 /// </summary> /// <param name="xmlRequest"> ...

  7. Topcoder几例C++字符串应用

    本文写于9月初,是利用Topcoder准备应聘时的机试环节临时补习的C++的一部分内容.签约之后,没有再进行练习,此文暂告一段落. 换句话说,就是本文太监了,一直做草稿看着别扭,删掉又觉得可惜,索性发 ...

  8. Net分布式系统之二:CentOS系统搭建Nginx负载均衡

    一.关于CentOS系统介绍 CentOS(Community Enterprise Operating System,中文意思是:社区企业操作系统)是Linux发行版之一,它是来自于Red Hat ...

  9. Python第一模块

    一.Python简介 二.Python种类 三.Python环境  windows: 1.需要配置环境变量 2.更新:卸载重装 linux:1.常用命令: 查看默认Python版本 Python -V ...

  10. MySQL数据库引擎介绍、区别、创建和性能测试的深入分析

    本篇文章是对MySQL数据库引擎介绍.区别.创建和性能测试进行了详细的分析介绍,需要的朋友参考下   数据库引擎介绍 MySQL数据库引擎取决于MySQL在安装的时候是如何被编译的.要添加一个新的引擎 ...