//

//  CollectionViewController.swift

//  tab

//

//  Created by su on 15/12/8.

//  Copyright © 2015年 tian. All rights reserved.

//

import UIKit

class CollectionViewController: UIViewController, UICollectionViewDelegate, UICollectionViewDataSource {

var collectionView: UICollectionView!

override func viewDidLoad() {

super.viewDidLoad()

let flowLayout = UICollectionViewFlowLayout()

flowLayout.itemSize = CGSize(width: (Tools().SCREEN_WIDTH - 30) / 3, height: (Tools().SCREEN_WIDTH - 30) / 3)

collectionView = UICollectionView(frame: self.view.bounds, collectionViewLayout: flowLayout)

collectionView.backgroundColor = UIColor.whiteColor()

collectionView.registerNib(UINib(nibName: "CollectionViewCell", bundle: nil), forCellWithReuseIdentifier: "CollectionViewCell")

collectionView.delegate = self

collectionView.dataSource = self

self.view.addSubview(collectionView)

}

func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {

return 10

}

func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {

let cell = collectionView.dequeueReusableCellWithReuseIdentifier("CollectionViewCell", forIndexPath: indexPath)

return cell

}

override func didReceiveMemoryWarning() {

super.didReceiveMemoryWarning()

// Dispose of any resources that can be recreated.

}

/*

// MARK: - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {

// Get the new view controller using segue.destinationViewController.

// Pass the selected object to the new view controller.

}

*/

}

swift 创建UICollectionView的更多相关文章

  1. swift:创建表格UITableView

    用swift创建单元格和用iOS创建单元格形式基本相同,就是语法上有些异样.swift中调用成员方法不再使用[ ]来发送消息,而是使用.成员方法的形式调用成员函数.这种格式非常类似于java中的点成员 ...

  2. 使用OC和swift创建系统自带的刷新界面

    使用OC和swift创建系统自带的刷新界面 一:swift刷新界面代码: import UIKit class ViewController: UITableViewController { // 用 ...

  3. OC与Swift创建pod

    Cocoa pods 是iOS最常用的类库管理工具   OC的使用   删除源   sudo gem sources -r https://rubygems.org/ 添加源(使用淘宝的镜像,记住要用 ...

  4. iOS开发 纯代码创建UICollectionView

    转:http://jingyan.baidu.com/article/eb9f7b6d8a81a5869364e8a6.html iOS开发 纯代码创建UICollectionView 习惯了使用xi ...

  5. swift 创建单例模式

    一.意图 保证一个类公有一个实例,并提供一个访问它的全局访问点. 二.使用场景 1.使用场景 当类只能有一个实例而且客户可以从一个众所周知的访问点访问它时 当这个唯一实例应该是通过子类化可扩展的,并且 ...

  6. swift 创建桥接头文件

    1,创建iOS 下source模块里的header file 文件,这个文件要注意命名的规则:xxx-Brigding-Header.h 2,到build setting 里 Swift Compil ...

  7. [译] 用 Swift 创建自定义的键盘

    本文翻译自 How to make a custom keyboard in iOS 8 using Swift 我将讲解一些关于键盘扩展的基本知识,然后使用iOS 8 提供的新应用扩展API来创建一 ...

  8. 你会用swift创建复杂的加载动画吗(1)

    时至今日,iOS 应用商店已经拥有超过了140万 应用,让你自己的应用脱颖而出确实是个不小的挑战.不过,在你的应用掉入默默无闻的大黑洞之前,你拥有一个小小的机遇窗,它能帮你吸引用户的注意. AD: 时 ...

  9. [Swift]创建CoreData的两种方式

    一.CoreData介绍 CoreData主要分为两部分: 上层是模型层,模型层有NSManagedObjectContext上下文管理着, 底层则是由SQLite实现的持久化部分,通过NSPersi ...

随机推荐

  1. LINQ to SQL 建立实体类 (转)

    http://www.cnblogs.com/DebugLZQ/archive/2012/11/14/2770449.html 使用LINQ to SQL时,需要首先建立用于映射数据库对象的模型,也就 ...

  2. 【linux】用户与组

    一.用户和组的基本概念                                               1.用户 用户:用于获取计算机资源或服务的标识符,比如用户名.计算机处理的是UID, ...

  3. 全是干货!UI设计的30条黄金准则!

    http://www.wex5.com/portfolio-items/js-1/ 全是干货!UI设计的30条黄金准则!   总的来说,好的UI界面有几个特征:简洁.便利.目标明确.人性化.字面上看这 ...

  4. 如何ping别人的计算机名来获取IP?

    来源:http://blog.csdn.net/qq_27109081/article/details/47128175 如何ping别人的计算机名来获取IP?            获取别人的IP, ...

  5. 安装wamp 缺少msvcr100.dll

    在一台新电脑上安装wampsever 这是百度上的解决方案,http://jingyan.baidu.com/article/0320e2c1eb49681b87507ba4.html 本人亲测 第一 ...

  6. Could not write content: No serializer found for class and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) )

    1. 问题 org.springframework.http.converter.HttpMessageNotWritableException: Could not write content: N ...

  7. C++ 构造函数_初始化列表

    构造函数初始化列表以一个冒号开始,接着是以逗号分隔的数据成员列表,每个数据成员后面跟一个放在括号中的初始化式.例如: class Student { public: //构造函数初始化列表 Stude ...

  8. zookeeper 运维

    尽管zookeeper在编程上有很多的阱陷,API也非常的难用,但zookeeper服务本身可以说是很牢靠的了,所以在网上貌似关于运维的文章比较少. 但省心并不代表不会出麻烦,下面总结下zookeep ...

  9. java之Jsch实现Linux的文件上传与下载

    一.JSch是Java Secure Channel的缩写.JSch是一个SSH2的纯Java实现.它允许你连接到一个SSH服务器,并且可以使用端口转发,X11转发,文件传输等,当然你也可以集成它的功 ...

  10. 关于diskgenius删除所有分区后,电脑不能识别U盘的问题。

    楼主曾今为了将Linux系统安装至U盘中,曾无数次对U盘进行过格式化,到最后导致,u盘各种引导.系统.烂数据存在U盘,导致U盘的使用越来越不方便.后来终于下狠心,利用diskgenius对U盘进行一次 ...