UICollectionViewCell with image without custom Class
UICollectionViewCell with image without custom Class
实际上有一个非常简单的问题:
我想要一个 collectionView 和一个与 Cell 大小相同的图像。我想在不构建额外的 class 的情况下完成这一切,所以从情节提要(也许,如果我进入我的子视图?!)
顺便说一句,我从网络加载数据,所以我不能每次都添加一个新的 ImageView....
就想问问这可行吗?!
干杯
如果您有静态集合视图,那么您可以不使用自定义视图 class
但是你有动态集合视图,那么你需要创建自定义 class。
看起来像这样。
class AddAlbumCell: UICollectionViewCell {
@IBOutlet var imgv: UIImageView!
}
在您的集合视图委托方法中
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("Cell", forIndexPath: indexPath) as! AddAlbumCell
cell.imgv.image = images[indexPath.row] //"images" contains image name array
return cell;
}
实际上有一个非常简单的问题: 我想要一个 collectionView 和一个与 Cell 大小相同的图像。我想在不构建额外的 class 的情况下完成这一切,所以从情节提要(也许,如果我进入我的子视图?!)
顺便说一句,我从网络加载数据,所以我不能每次都添加一个新的 ImageView....
就想问问这可行吗?!
干杯
如果您有静态集合视图,那么您可以不使用自定义视图 class 但是你有动态集合视图,那么你需要创建自定义 class。 看起来像这样。
class AddAlbumCell: UICollectionViewCell {
@IBOutlet var imgv: UIImageView!
}
在您的集合视图委托方法中
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("Cell", forIndexPath: indexPath) as! AddAlbumCell
cell.imgv.image = images[indexPath.row] //"images" contains image name array
return cell;
}