title: How to dynamically change an image in an Image View?
body: <p>Basically, I have a main UIImageView which I then programmatically add another Image View (with image) on top. What I would like to do is dynamically swap out the image on click, but when I attempt to do so the image does not show. 
  Here's what I've implemented so far:</p>
  
  <p>In Storyboard:    //mainImgView</p>
  
  <p><img src="https://i.stack.imgur.com/fcXZI.png" alt="enter image description here"></p>
  
  <p>In.h:</p>
  
  <pre><code>#import "ViewController.h"
  @interface ViewController ()
       @property (nonatomic, strong) UIImageView *overlayImgView;
  @end
  </code></pre>
  
  <p>In.m:</p>
  
  <pre><code>-(IBAction) addOverlayImgViewWImgToMainImgView:(UIButton *)sender{    
      UIImage *tempImg1 = [UIImage imageNamed:@"xcode_icon.png"];
  
      self.overlayImgView = [[UIImageView alloc]initWithImage:tempImg1];
      [mainImgView addSubview:self.overlayImgView];   
  }
  
  -(IBAction) swapImg:(UIButton *)sender{
      UIImage *tempImg2 = [UIImage imageNamed:@"another_icon.png"];
      [self.overlayImgView setImage:tempImg2];
  }
  </code></pre>
  
  <p>If someone could please shed some light on what I’m doing wrong, it would be much appreciated. Thank you.</p>
  
  <p>Among the links I've looked at are:</p>
  
  <p><a href="https://stackoverflow.com/questions/22571075/ios-how-to-dynamically-add-image-to-a-parent-view">iOS: How to dynamically add image to a parent view?</a></p>
  
  <p><a href="https://stackoverflow.com/questions/10998544/uiimage-imagenamed-returns-nil/10998746#10998746">UIImage imageNamed returns nil</a></p>
  
  <p><a href="https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIImageView_Class/Reference/Reference.html#//apple_ref/occ/instm/UIImageView/initWithImage" rel="nofollow noreferrer">https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIImageView_Class/Reference/Reference.html#//apple_ref/occ/instm/UIImageView/initWithImage</a>:</p>
  
  <p>Additional Info:</p>
  
  <p>There's already an image on the main Image View and I'm adding a smaller (50x50) Image View (w/ image) to it. When I try to swap it out, the current image is disappearing then replace with a white box.</p>
  
  <p>The image files are 50x50 and are in my 'Supported Files' folder. I do not have a second '@2X' image.</p>