2016-12-15 17 views
0

目前我工作的一个项目,我的产品页面是这样的 enter image description here我怎么通过的CollectionView选择更改单元格的图像

这里我使用的是的UIImageView显示大图及以下我正在使用CollectionView滚动一组图像。我想要点击CollectionViewCell中的图像时相应地更改大图像。由于这是我第一次使用这种功能,我不知道。请有人给我一些建议。谢谢。

+0

使用collectionview delegates –

+0

您可以分享您的代码,以便我们为您提供帮助吗? –

回答

1

如果每个图像是在一个单独的UICollectionViewCell,使用

override func collectionView(_ collectionView: UICollectionView, 
          didSelectItemAt indexPath: IndexPath) { 
    // here you know which item is selected by accessing indexPath.item property, for example: 
    let selectedImage = yourImages[indexPath.item] 
    bigImageView.image = selectedImage 
} 

方法当用户选择一个集合视图项目来检测。 为了使用这种方法,您需要符合UICollectionViewDelegate并设置collectionView.delegate = self

+0

哇!那就是我正在寻找的。谢谢 。 –

相关问题