Swift:如何更改imageView颜色看起来像是被点击了?

时间:2015-11-28 22:53:25

标签: ios swift

我在单元格内部有一个imageView。但是,当我点击那个单元格时,没有任何可视指示器被点击。我希望它看起来与按钮内的imageView相同,当你点击按钮时它会改变颜色。

  func collectionView(collectionView: UICollectionView, shouldHighlightItemAtIndexPath indexPath: NSIndexPath) -> Bool {
    let cell: UICollectionViewCell = collectionView.cellForItemAtIndexPath(indexPath)

    // what do i do with the cell.imageView to change it's state to look like it was tapped?
  }

1 个答案:

答案 0 :(得分:1)

  func collectionView(collectionView: UICollectionView, shouldHighlightItemAtIndexPath indexPath: NSIndexPath) -> Bool {
    let cell: IconCell = collectionView.cellForItemAtIndexPath(indexPath) as! IconCell
    cell.imageView.alpha = 0.5
    return true
  }

  func collectionView(collectionView: UICollectionView, didUnhighlightItemAtIndexPath indexPath: NSIndexPath) {
    let cell: IconCell = collectionView.cellForItemAtIndexPath(indexPath) as! IconCell
    cell.imageView.alpha = 1.0
  }