UICollectionView swift2模版
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模版的更多相关文章
- [IOS UICollectionView模版]
创建CollectionCell模版: 1.新建类CollectionCell继承自UICollectionViewCell 2.新建Xib,命名为CollectionCell.xib a.选中Col ...
- 【iOS】UICollectionView自己定义Layout之蜂窝布局
网上的UICollectionView的Layout布局,其cell的形状多为矩形和圆形. 本篇博文将正六边形作为cell的基本形状,为您展现独特的蜂窝布局效果及实现源代码. 帮助您让自己的App脱颖 ...
- 【iOS】Xcode8+Swift3 纯代码模式实现 UICollectionView
开发环境 macOS Sierra 10.12.Xcode 8.0,如下图所示: 总体思路 1.建立空白的storyboard用于呈现列表 2.实现自定义单个单元格(继承自:UICollectionV ...
- 创建ABPboilerplate模版项目
本文是根据角落的白板报的<通过ABPboilerplate模版创建项目>一文的学习总结,感谢原文作者角落的白板报. 1 准备 开发环境: Visual Studio 2015 update ...
- 使用boilerplate模版创建解决方案
返回总目录<一步一步使用ABP框架搭建正式项目系列教程> 话不多说,让我们开始干吧!对于还没有接触ABP框架或者接触时间还不是很长的小伙伴来说,我建议还是使用官方建议的做法,那就是到ABP ...
- ASP.NET MVC5+EF6+EasyUI 后台管理系统(29)-T4模版
系列目录 本节不再适合本系统,在58,59节已经重构.请超过本节 这讲适合所有的MVC程序 很荣幸,我们的系统有了体验的地址了.演示地址 之前我们发布了一个简单的代码生成器,其原理就是读取数据库的表结 ...
- 构建自己的PHP框架--构建模版引擎(1)
前段时间太忙,导致好久都没有更新博客了,今天抽出点时间来写一篇. 其实这个系列的博客很久没有更新了,之前想好好规划一下,再继续写,然后就放下了,今天再捡起来继续更新. 今天我们来说一下,如何构建自己的 ...
- 使用UICollectionView实现首页的滚动效果
实现类似这样的效果,可以滚动大概有两种实现方案 1. 使用scrollview来实现 2. 使用UICollectionView来实现 第一种比较简单,而且相对于性能来说不太好,于是我们使用第二种方案 ...
- asp.net读取模版并写入文本文件
本文要介绍的是ASP.NET怎样读写文本文件,但更重要的是实现的过程.使用的工具是Visual Studio 2015 ,.NET版本是4.6.1 .一共建立的2个项目,HoverTreePanel和 ...
随机推荐
- jq之ajax以及json数据传递
<html> <head><meta http-equiv="Content-Type" content="text/html; chars ...
- MySQL_采购入库价格与在线售价监控_20161213
c037采购入库价格与在线售价监控 ##c037采购入库价格与在线售价监控 SELECT a.城市,a.产品ID,a.商品名称,a.入库日期,a.入库仓库,a.单价,a.总金额,a.采购人,b.单价 ...
- JS Json数据转换
*** json字符串中不能出现单引号,不然JSON.parse会报错,处理方式将单引号转义 概述 JSON.stringify() 方法可以将任意的 JavaScript 值序列化成 JSON 字符 ...
- 315. Count of Smaller Numbers After Self
You are given an integer array nums and you have to return a new counts array. The counts array has ...
- Math
Math.sin(t) // sin(t) Math.power(x,2*i) // x的2i次方 (double)(Math.round(sum*1000000))/1000000; / ...
- Appium学习路—Android定位元素与操作
一.常用识别元素的工具 uiautomator:Android SDK自带的一个工具,在tools目录下 monitor:Android SDK自带的一个工具,在tools目录下 Appium Ins ...
- Android Studio使用百度地图示例BaiduMapsApiASDemo
Android Studio使用百度地图示例BaiduMapsApiASDemo 用自己AVD下的debug.keystore替换掉项目中的debug.keystore 生成自己的签名 同样的方法生成 ...
- StaticPagedList
估计是因为水平原因,之前看别人写的用pagedList分页,老是云里雾里的.下面把自己写的整理一下放在上面.这里的List为对应页面展示的内容.不用查询所有. Action: public Actio ...
- EF外键关联
客户里面存在客服外键 基类模型 public class ModelBase { public ModelBase() { CreateTime = DateTime.Now; } [Key] pub ...
- Spring Framework------>version4.3.5.RELAESE----->Reference Documentation学习心得----->Spring Framework中的spring web MVC模块
spring framework中的spring web MVC模块 1.概述 spring web mvc是spring框架中的一个模块 spring web mvc实现了web的MVC架构模式,可 ...