1,layout@H_301_3@
该属性表示布局方式,有Flow、Custom两种布局方式。默认是Flow流式布局。
2,Accessories@H_301_3@
是否显示页眉和页脚
Cell Size:单元格尺寸
Header Size:页眉尺寸
Footer Size:页脚尺寸
Min Spacing:单元格之间间距
Section Insets:格分区上下左右空白区域大小。
二、流布局的简单样例@H_301_3@
1,先创建一个应用Simple View Application,删除默认的
View Controller@H_301_3@,拖入一个
Collection View Controller@H_301_3@到界面上,这时我们可以看到已经同时添加了
Collection View@H_301_3@和
Collection View Cell@H_301_3@控件。
4,设置
Image View@H_301_3@的
tag@H_301_3@为
1@H_301_3@,
Label@H_301_3@的
2@H_301_3@,
Colletion View Cell@H_301_3@的
Identifier@H_301_3@为
DesignViewCell@H_301_3@。
--- ViewController.swift ---@H_301_3@
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
2
|
import
UIKit
class
ViewController: UICollectionViewController {
let courses = [
[
"name"
:
"Swift"
,
"pic"
"swift.png"
],
]
override
func viewDidLoad() {
super
.viewDidLoad()
// 已经在界面上设计了Cell并定义了identity,不需要注册CollectionViewCell
//self.collectionView.registerClass(UICollectionViewCell.self,
// forCellWithReuseIdentifier: "DesignViewCell")
self.collectionView?.backgroundColor = UIColor.whiteColor()
}
func collectionView(collectionView: UICollectionView,
numberOfItemsInSection section: Int) -> Int {
return
courses.count;
}
// 获取单元格
cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
// storyboard里设计的单元格
let identify:
String
=
"DesignViewCell"
let cell = (self.collectionView?.dequeueReusableCellWithReuseIdentifier(
identify,forIndexPath: indexPath))!
as
UICollectionViewCell
// 从界面查找到控件元素并设置属性
(cell.contentView.viewWithTag(
1
)
! UIImageView).image =
UIImage(named: courses[indexPath.item][
]!)
2
! UILabel).text =
courses[indexPath.item][
]
cell
}
func didReceiveMemoryWarning() {
.didReceiveMemoryWarning()
}
|