Swift4.0 學習筆記 第十一節: UICollectionView

//
//  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) {
    }
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章