美文网首页
swift-14collectionView

swift-14collectionView

作者: sunmumu1222 | 来源:发表于2017-08-30 09:06 被阅读7次

    我以前做的swift笔记, 之前都是整理在onenote上, 最近想到整理出博客. 也方便自己查找, 可以当做自己的一份文档.

    import UIKit
    
    class ViewController: UIViewController, UICollectionViewDataSource, UICollectionViewDelegate {
    
        override func viewDidLoad() {
            super.viewDidLoad()
            setupUI()
        }
    
        func setupUI() {
            let flowLayout = UICollectionViewFlowLayout.init()
            flowLayout.itemSize = CGSize(width: 100, height: 100)
            
            let collectionView = UICollectionView.init(frame: view.bounds, collectionViewLayout: flowLayout)
            view.addSubview(collectionView)
            collectionView.register(UICollectionViewCell.self, forCellWithReuseIdentifier: "cellID")
            collectionView.dataSource = self
            collectionView.delegate = self
            
            collectionView.backgroundColor = UIColor.white
            
        }
        
        func numberOfSections(in collectionView: UICollectionView) -> Int {
            return 1
        }
    
        func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
            return 20
        }
        
        func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
            let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cellID", for: indexPath)
            cell.backgroundColor = UIColor.blue
            return cell
        }
        
        //移动
        func collectionView(_ collectionView: UICollectionView, moveItemAt sourceIndexPath: IndexPath, to destinationIndexPath: IndexPath) {
            
        }
        
    }
    

    相关文章

      网友评论

          本文标题:swift-14collectionView

          本文链接:https://www.haomeiwen.com/subject/asszdxtx.html