//
// 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) {
}
}