繁体   English   中英

UICollectionViewCell具有不带自定义类的图像

[英]UICollectionViewCell with image without custom Class

那里实际上是一个非常简单的问题:我想要一个CollectionView,其Image与Cell的大小相同。 我想在不建立额外的类的情况下完成所有操作,所以从情节提要(也许,如果我进入子视图?!)

顺便说一句,我从Web加载数据,所以我不能每次都添加一个新的ImageView。

只是想问问这有可能吗?

干杯

如果您具有静态的Collection视图,则可以不使用自定义类,但是您可以使用动态的Collection视图,则需要创建自定义类。 看起来像这样

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;
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM