how do I change an image by selecting a cell in CollectionView

六眼飞鱼酱① 提交于 2019-12-12 01:57:02

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!