Sae*_*ahi 3 image ios uicollectionview uicollectionviewcell swift3
我正在使用swift 3 - 我知道如何使用自定义Cell在集合视图中显示一些图像 - 问题是我无法在集合视图控制器中使用自定义单元
这里是集合视图控制器代码私有让reuseIdentifier ="uploadCell"
class uploadedFiles:UICollectionViewController {
var images = ["1.jpg" , "2.jpg" , "3.jpg" , "4.jpg" ]
override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: reuseIdentifier, for: indexPath)
//myCollectionView.sizeToFit()
//cell.sizeToFit()
cell.cellImages.image = UIImage(named: images[indexPath.row])
return cell
}
Run Code Online (Sandbox Code Playgroud)
这是收集视图单元代码
import UIKit
class UICollectionViewCell: UICollectionViewCell {
@IBOutlet weak var cellImages: UIImageView!
}
Run Code Online (Sandbox Code Playgroud)
记得我用"uploadCell"作为标识符
用于使用CollectionView Custom Cell
第1步:创建CollectionViewCell的子类
class ImageCell: UICollectionViewCell {
@IBOutlet weak var imgView: UIImageView!
}
Run Code Online (Sandbox Code Playgroud)
第2步:在StoryBoard中设置CollectionViewCell类
第3步:reuseCollectionView Cell
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "ImageCell", for: indexPath) as! ImageCell
cell.imgView.image = self.arrMedia[indexPath.row] as? UIImage
return cell
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
5533 次 |
最近记录: |