title: Adding UIButtons to uiimage of a UICollectionView cells programmatically
body: <p>I have a UIViewController with a UICollectionView image gallery created inside it programmatically. I want to add a button to the on each uiimage of UICollectionView cell: The code in CMFViewController.h.m file for adding button to imageview is:</p>
  
  <pre><code>-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
  
      CMFGalleryCell *cell = (CMFGalleryCell *)[collectionView dequeueReusableCellWithReuseIdentifier:@"cellIdentifier" forIndexPath:indexPath];
  
      NSString *imageName = [self.dataArray objectAtIndex:indexPath.row];
      [cell setImageName:imageName];
     // [[cell myButton] addTarget:self action:@selector(myClickEvent:event) forControlEvents:UIControlEventTouchUpInside];
  
      UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
      button.frame = CGRectMake(80.0, 210.0, 100.0, 20.0);
      [button addTarget:self action:@selector(show) forControlEvents:UIControlEventTouchUpInside];
      [button setTitle:@"ShowView" forState:UIControlStateNormal];
  
    //  NSMutableArray *buttonArray = [NSMutableArray arrayWithCapacity:100];
  
    //  for (int i = 0; i &lt; 4; i++) {
         // NSUInteger index = arc4random() % 4;
  
  
          // newButton.frame = CGRectMake( 5,  5, 10, 10);    // Whatever position and size you need...
  
         // UIImage *buttonImage = [UIImage imageNamed:[self.dataArray objectAtIndex:indexPath.row]];
          //[newButton setBackgroundImage:buttonImage forState:UIControlStateNormal];
  
       //   [buttonArray addObject:newButton];
    //  }
     // newButton = buttonArray;   // Where myButtons is a NSArray property of your class, to store references to the buttons.
  
     // [newButton addTarget:self action:@selector(loadImages:) forControlEvents:UIControlEventTouchUpInside];
      //[newButton addTarget:self action:@selector(updateCell) forControlEvents:UIControlEventTouchUpInside];
  
      [cell updateCell];
  
      return cell;
  
  }
  </code></pre>
  
  <p>I have tied to get help from codes at following links
  <a href="https://stackoverflow.com/questions/17843533/adding-a-uibutton-to-a-uicollectionview-cell-programmatically">adding-a-uibutton-to-a-uicollectionview</a></p>
  
  <p><a href="https://stackoverflow.com/questions/13218208/uibutton-in-cell-in-collection-view-not-receiving-touch-up-inside-event?rq=1">UIButton in cell in collection view not receiving touch up inside event</a>
  Please give my your suggestion and help me on this issue.</p>
  
  <p>from this link u can download <a href="https://github.com/timd/UICollectionViewGallery" rel="nofollow noreferrer">source code</a>  in <a href="http://adoptioncurve.net/archives/2013/04/creating-a-paged-photo-gallery-with-a-uicollectionview/" rel="nofollow noreferrer">Creating a Paged Photo Gallery With a UICollectionView</a>:  their i want to place next and previous buttons on middle lines of each image of the screen</p>