【问题标题】:how do I change an image by selecting a cell in CollectionView如何通过在 CollectionView 中选择一个单元格来更改图像
【发布时间】:2017-05-01 00:00:40
【问题描述】:
目前我正在做一个项目,我的产品页面是这样的
这里我使用 UIImageView 来显示大图像,在下面我使用 CollectionView 来滚动一组图像。当我单击 CollectionViewCell 中的图像时,我想相应地更改大图像。由于这是我第一次使用这种功能,我一无所知。请任何人给我一些建议。谢谢。
【问题讨论】:
标签:
ios
swift
swift3
collectionview
【解决方案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