---
title: "How to change the background color of UICollectionView cell in iOS?"  
description: "How to change the background color of UICollectionView cell in iOS?"  
author: "Anonymous User"  
published: 2015-12-23  
updated: 2015-12-23  
canonical: https://www.mindstick.com/forum/33777/how-to-change-the-background-color-of-uicollectionview-cell-in-ios  
category: "iphone"  
tags: ["iphone", "ios", "objective c"]  
reading_time: 1 minute  

---

# How to change the background color of UICollectionView cell in iOS?

I have created an [application](https://www.mindstick.com/articles/12824/calculator-application-in-android) using UICollectionView, and adding some [images](https://www.mindstick.com/interview/1067/what-is-the-php-predefined-variable-that-tells-the-what-type-of-images-that-php-support) into the [collection view](https://www.mindstick.com/forum/33803/how-to-set-collection-view-cell-size-in-ios) cell.\
Now I want to change the cell [background color](https://www.mindstick.com/forum/12937/how-to-style-togglebutton-so-that-the-background-color-is-white) 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](https://www.mindstick.com/blog/136/using-watermark-functionality-in-textbox-by-jquery) similar like in UITableViewCell willSelectItemAtIndexPath: method.\
[Please suggest](https://answers.mindstick.com/qa/43506/please-suggest-the-bathing-date-at-kumbh) me any solution.

## Replies

### Reply by Tarun Kumar

If you want to change the [background](https://www.mindstick.com/articles/65/how-to-change-background-color-of-tab-control-in-c-sharp) with different color on different cell selection, then you can try [collection](https://www.mindstick.com/articles/1718/collections-in-java) view method **didSelectedItemAtIndexPath**: and **didDeselectItemAtIndexPath**: .\
Here is both example:

```
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{    UICollectionViewCell *cell = [collectionView cellForItemAtIndexPath:indexPath];    cell.backgroundColor = [UIColor yellowColor];} - (void)collectionView:(UICollectionView *)collectionView didDeselectItemAtIndexPath:(NSIndexPath *)indexPath{    UICollectionViewCell *cell = [collectionView cellForItemAtIndexPath:indexPath];    cell.backgroundColor = [UIColor clearColor];}
```


---

Original Source: https://www.mindstick.com/forum/33777/how-to-change-the-background-color-of-uicollectionview-cell-in-ios

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
