Reputation: 2121
I have added an imageview
, and i am trying to add an button over it. How to do it.
self.imgview = [UIImageView alloc]initWithImage:[UIImage imageNamed:@"f.png"]];
[self.imgview addSubView:button];
[self.view addSubView:imgView];
What i get is the f.png
Image, i dont see the button that i added over it. How could i resolve this ?
I have no idea what is wrong and i have been stuck in this problem for hours. I need your help
Upvotes: 0
Views: 471
Reputation: 36
You need to set the views' frames:
self.imgview = [UIImageView alloc]initWithImage:[UIImage imageNamed:@"f.png"]];
self.button = [[UIButton alloc] init];
[imgview setFrame:CGRectMake(100,100,100,100)];
[button setFrame:CGRectMake(100,100,100,100)];
[self.view addSubView:imgView];
[self.view addSubView:button];
Upvotes: 2
Reputation: 3772
self.imgview = [UIImageView alloc]initWithImage:[UIImage imageNamed:@"f.png"]];
[self.view addSubView:imgView];
[self.view addSubView:button];
Just add them both to the view, adding the button after the image so that it composes on top of the image. Assuming their frame's x,y coordinates also match up.
Upvotes: 0