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和 ...
随机推荐
- 类似于QQ的简单的聊天代码
先编辑页面 package com.lovo.feichun; import java.awt.Color;import java.awt.Component;import java.awt.Cont ...
- Myeclispe 安装 SVN :
Myeclispe 安装 SVN :解压 : site-1.8.22.zip 放入如下路径下即可 :
- jQuery中的end()
要说end(),我们就不得不说prevObject. 在jQuery中,每个jQuery对象都有一个prevObject属性 var $p = $('p'); 这个属性是做什么的呢? jQuery内部 ...
- Python语法一
前记,今天开始学习Python 参考 笨方法学习+Python(第三版) 因为有编程基础,所以入门不难,相比于以前学过的其它语言编程,Python当然也有它独特的语法格式. 1.安装Python 访问 ...
- web初学之JavaBean
JavaBean 1.javaBean类:特殊的java类,以封装和重用为目的.通常JavaBean与Jsp搭配使用构成JavaBean技术. (1)JavaBean的规范: ●JavaBean是个公 ...
- WPF 大数据加载过程中的等待效果——圆圈转动
大家肯定遇到过或将要遇到加载大数据的时候,如果出现长时间的空白等待,一般人的概念会是:难道卡死了? 作为一个懂技术的挨踢技术,即使你明知道数据量太大正在加载,但是假如看不到任何动静,自己觉得还是一种很 ...
- html5 canvas画不出图像的原因
很久没写博客了,今年过年的时候,家里出了意外,现在心里依然很难受.6月份之前一直忙着写毕业论文,答辩完6月初回公司继续上班,今天刚好周末有空,就写下之前碰到一个问题. 做一个图像查看器(基于Chrom ...
- php如何获取当前时间
$nowtime=date('Y-m-d'); 这样取出来的值默认为当天的零点,对于做一些数据统计的sql查询比较有用
- Form提交是会刷新页面的
今天发现如果页面中有form,点击提交按钮是会刷新页面的,为了禁止页面刷新行为,可以这么做: <form class="form-horizontal" id="u ...
- 初学c# -- 学习笔记(四)
想想,数据库先用mysql了,这玩意小且安装方便.前面web学了些,现在学winform的.数据库先看看便捷的mysql. 下载了一个mysql5.7版的,装上居然找不到密码,重装3.4回,找不到,说 ...