UICollectionView Cell with Image, change Background with click
ios, objective-c, uicollectionview, uicollectionviewcell
Solution
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
}
}
Problem
I have a `UICollectionView` with `Custom CollectionView Cells`. On each Cell there is a Image on it, which is as big as the whole Cell. Now i want to highlight the Cell when the User touches the Cell. First i tried it with the following `delegate Methods`: ``` - (void)collectionView:(UICollectionView *)collectionView didHighlightItemAtIndexPath:(NSIndexPath *)indexPath { UICollectionViewCell* cell = [self.collectionView cellForItemAtIndexPath:indexPath]; cell.contentView.backgroundColor = [UIColor redColor]; } - (void)collectionView:(UICollectionView *)collectionView didUnhighlightItemAtIndexPath:(NSIndexPath *)indexPath { UICollectionViewCell *cell = [self.collectionView cellForItemAtIndexPath:indexPath]; cell.contentView.backgroundColor = [UIColor clearColor]; } ``` But nothing happend.After i deleted the Images from the Cells it worked perfectly. But with the Images nothing happens! What else can I do?