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:
In Storyboard: //mainImgView
In.h:
#import "ViewController.h"
@interface ViewController ()
@property (nonatomic, strong) UIImageView *overlayImgView;
@end
In.m:
-(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];
}
If someone could please shed some light on what I’m doing wrong, it would be much appreciated. Thank you.
Among the links I've looked at are:
iOS: How to dynamically add image to a parent view?
UIImage imageNamed returns nil
Additional Info:
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.
The image files are 50x50 and are in my 'Supported Files' folder. I do not have a second '@2X' image.