I have created an application using UICollectionView, and adding some images into the collection view cell.
Now I want to change the cell background color whenever the element is tapped.
I have tried by this code:
-(void) collectionView:(UICollectionView *)collectionView didHighlightItemAtIndexPath:(NSIndexPath *)indexPath{
//change color when tapped
}-(void)collectionView:(UICollectionView *)collectionView didUnhighlightItemAtIndexPath:(NSIndexPath *)indexPath{
//change back on touch up
}
It works but it will change only when I keep my finger for a bit longer time.
Can you tell me is there any functionality similar like in UITableViewCell willSelectItemAtIndexPath: method.
Please suggest me any solution.
Tarun Kumar
23-Dec-2015If you want to change the background with different color on different cell selection, then you can try collection view method didSelectedItemAtIndexPath: and didDeselectItemAtIndexPath: .
Here is both example: