簡體   English   中英

如何通過在CollectionView中選擇一個單元格來更改圖像

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

目前,我正在一個項目上,我的產品頁面是這樣的 在此處輸入圖片說明

在這里,我使用UIImageView來顯示大圖像,而在下面,我使用CollectionView來滾動圖像集。 當我從CollectionViewCell單擊圖像時,我想相應地更改大圖像。 由於這是我第一次使用這種功能,因此我一無所知。 請任何人給我一些建議。 謝謝。

如果每個圖像都在單獨的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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM