I have a Collection View that looks like this:
The blue border is an image. When I press them I want the text and the image to dim briefly.
I found this SO question that is similar:
- UICollectionView Cell with Image, change Background with click
And it included this answer in Objective-C:
If you have a CustomCell, you must have a CustomCell.m (implementation file). In this file add this, to me is the easy way:
-(void)setHighlighted:(BOOL)highlighted { if (highlighted) { self.layer.opacity = 0.6; // Here what do you want. } else{ self.layer.opacity = 1.0; // Here all change need go back } }
I tried adding this to my custom UICollectionViewCell
like this:
import UIKit
class DoubleSoundsCollectionViewCell: UICollectionViewCell {
@IBOutlet weak var cellLabel: UILabel!
func highlighted(highlighted: Bool) {
if (highlighted)
{
self.layer.opacity = 0.6;
// Here what do you want.
}
else{
self.layer.opacity = 1.0;
// Here all change need go back
}
}
}
But there was no noticeable effect on my collection view when I tap a cell. Did I add it in the wrong place or did I convert it to Swift in the wrong way?
If I call the method setHighlighed
, then I get the error
[PATH]/DoubleSoundsCollectionViewCell.swift:15:10: Method 'setHighlighted' with Objective-C selector 'setHighlighted:' conflicts with setter for 'highlighted' from superclass 'UICollectionViewCell' with the same Objective-C selector