Kishore kumar
Kishore kumar

Reputation: 143

how to change collection view cell background colour when it is selected?

This code is I used if cell is selected then the background colour have to change in image view it is placed inside the collection view cell. But its not working

-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
  {
      if (cell.selected) {
        cell.img_cell.backgroundColor = [UIColor colorFromHexString:@"#ffc400"]; // highlight selection
      }
      else
      {
        cell.backgroundColor = [UIColor clearColor]; // Default color
      }
      NSLog(@"Selected section>> %@",[arr_images objectAtIndex:indexPath.row]);

      //    cell.backgroundColor=[UIColor colorFromHexString:@"#ffc400"];
  }

Upvotes: 1

Views: 2293

Answers (1)

Kishore kumar
Kishore kumar

Reputation: 143

now its working i removed the if condition and tried using cellForItemAtIndexPath .

cell = [collectionView cellForItemAtIndexPath:indexPath];

        cell.img_cell.backgroundColor = [UIColor colorFromHexString:@"#ffc400"]; // high

Upvotes: 2

Related Questions