How do I programmatically add a UIImage to a UIImageView then add that UIImageView to another UIView?
In your ViewController , add the imageview directly...
- (void)viewDidLoad
{
playerView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"playerIdle.png"]];
[self.view addSubView: playerView];
}
Try this:
UIImageView *imgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"name.png"]];
[self.view addSubview:imgView];
Pls try the below code :
- (id)init
{
if (self = [super init]) {
playerIdle = [UIImage imageNamed:@"playerIdle.png"];
playerView = [[UIImageView alloc] initWithImage:playerIdle];
[self.view addSubview:playerView];
}
return self;
}
Hope this might help you.....