//
// ViewController.swift
// 014-UICollectionView
//
// Created by 庄壮勇 on 2018/1/4.
// Copyright © 2018年 Personal. All rights reserved.
//
import UIKit
class ViewController: UICollectionViewController {
// 数据源方法
// 如果是使用 collectionViewController 数据源方法都有一个 ‘override’
override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 50
}
override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cellId", for: indexPath)
cell.backgroundColor = UIColor.init(red: CGFloat(arc4random()%256)/255.0, green: CGFloat(arc4random()%256)/255.0, blue: CGFloat(arc4random()%256)/255.0, alpha: 1)
return cell
}
// 移动cell
override func collectionView(_ collectionView: UICollectionView, moveItemAt sourceIndexPath: IndexPath, to destinationIndexPath: IndexPath) {
}
}
// ViewController.swift
// 014-UICollectionView
//
// Created by 庄壮勇 on 2018/1/4.
// Copyright © 2018年 Personal. All rights reserved.
//
import UIKit
class ViewController: UICollectionViewController {
// 数据源方法
// 如果是使用 collectionViewController 数据源方法都有一个 ‘override’
override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 50
}
override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cellId", for: indexPath)
cell.backgroundColor = UIColor.init(red: CGFloat(arc4random()%256)/255.0, green: CGFloat(arc4random()%256)/255.0, blue: CGFloat(arc4random()%256)/255.0, alpha: 1)
return cell
}
// 移动cell
override func collectionView(_ collectionView: UICollectionView, moveItemAt sourceIndexPath: IndexPath, to destinationIndexPath: IndexPath) {
}
}