0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Swift CollectionViewCell的使用

Last updated at Posted at 2018-01-04

Collection View 笔记
01 在故事板中拖一个Collection View控件,设置个图片,加一个imageView,设置它的大小,使其大小适应,
将ViewController的dataSource连接上,要是不连接的,在viewController中写 collentionView.Datasourece = self
Snip20180104_9.png
02 新建并指定ConllectionViewCell 对应的的类(继承UIviewControllerCell),设置它的Identifier
Snip20180104_12.png
Snip20180104_11.png
03 在ViewController中,让它继承UICollectionViewDataSource
Snip20180104_14.png
04 然后实现UICollectionViewDataSource协议的方法

func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        
        return  1//返回的行数
    }
    
    
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "myCell", for: indexPath)  as! myCellCollectionViewCell  // myCell是ConllectionViewCell的Identifier,as后面是ConllectionViewCell对应的类
        cell.imageView.image = UIImage(named: "moon-1859616_1920.jpg”)//图片的名字
        return cell //返回cell 的内容
    }

 源码 https://github.com/honest666/CollectionVeiwCell

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?