title: How to change the button image inside the UICollectionViewCell using for loop in ios
body: <p><a href="https://i.stack.imgur.com/6fizg.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/6fizg.png" alt=""></a>Am new to xcode.In below screenshoot in indexpath.row=0 to indexpath.row =4 am having x button and from indexpath.row=5 to indexpath.row=8 having + button.How should i write for loop condition to those buttons.Any help is appreciable.</p>
  
  <p>Here is my code.</p>
  
  <p>ViewController.m</p>
  
  <pre><code>- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
  {
      static NSString *cellID = @"cellID";
      RACollectionViewCell *cell = [self.collectionView dequeueReusableCellWithReuseIdentifier:cellID forIndexPath:indexPath];
  
      [cell.imageView removeFromSuperview];
      cell.imageView.frame = cell.bounds;
      cell.imageView.image = [UIImage imageNamed:[_photosArray objectAtIndex:indexPath.item]];
      cell.backgroundColor = [UIColor lightGrayColor];
      [cell.contentView addSubview:cell.imageView];
  
          UIButton *btn = [[UIButton alloc]init];
  
          [cell.imageView addSubview:btn];
  
          if (indexPath.item == 0)
          {
              UIImage *buttonImage = [UIImage imageNamed:@"ic_dele_photo"];
              [btn setBackgroundImage:buttonImage forState:UIControlStateNormal];
          }
  
         else if (indexPath.item == 1)
         {
              UIImage *buttonImage = [UIImage imageNamed:@"ic_dele_photo"];
              [btn setBackgroundImage:buttonImage forState:UIControlStateNormal];
         }
  
          else if (indexPath.item == 2)
          {
              UIImage *buttonImage = [UIImage imageNamed:@"ic_dele_photo"];
              [btn setBackgroundImage:buttonImage forState:UIControlStateNormal];
          }
  
          else if (indexPath.item == 3)
          {
              UIImage *buttonImage = [UIImage imageNamed:@"ic_dele_photo"];
              [btn setBackgroundImage:buttonImage forState:UIControlStateNormal];
          }
          else if (indexPath.item == 4)
          {
              UIImage *buttonImage = [UIImage imageNamed:@"ic_dele_photo"];
              [btn setBackgroundImage:buttonImage forState:UIControlStateNormal];
          }
          else if (indexPath.item == 5)
          {
              UIImage *buttonImage = [UIImage imageNamed:@"ic_add_photo"];
              [btn setBackgroundImage:buttonImage forState:UIControlStateNormal];
          }
          else if (indexPath.item == 6)
          {
              UIImage *buttonImage = [UIImage imageNamed:@"ic_add_photo"];
              [btn setBackgroundImage:buttonImage forState:UIControlStateNormal];
  
          }
          else if (indexPath.item == 7)
          {
              UIImage *buttonImage = [UIImage imageNamed:@"ic_add_photo"];
              [btn setBackgroundImage:buttonImage forState:UIControlStateNormal];
  
          }
          else if (indexPath.item == 8)
          {
              UIImage *buttonImage = [UIImage imageNamed:@"ic_add_photo"];
              [btn setBackgroundImage:buttonImage forState:UIControlStateNormal];
          }
  
          if (iPhone5)
          {
              btn.frame = CGRectMake(82, 82, 18, 18);
          }
          else if (iPhone6)
          {
              btn.frame = CGRectMake(101, 100, 18, 18);
  
          }
          else if (iPhone6Plus)
          {
              btn.frame = CGRectMake(112, 112, 18, 18);
  
          }
          else
          {
              btn.frame = CGRectMake(80, 80, 18, 18);
          }
  
      return cell;
  }
  </code></pre>