问题
Currently I am working on a project and my product page is like this
Here I am using an UIImageView to show the large image and below that I am using a CollectionView to scroll a set of images. I want to change the large image accordingly when I click an image from the CollectionViewCell . As this is the first time I am using this kind of functionality, I am out of clue. Please anybody give me some suggestion. Thank you.
回答1:
If every image is in a separate UICollectionViewCell, use
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
}
method to detect when user selects a collection view item.
In order to use this method you need to conform to UICollectionViewDelegate
and set collectionView.delegate = self
来源:https://stackoverflow.com/questions/41163222/how-do-i-change-an-image-by-selecting-a-cell-in-collectionview