2012-02-15 106 views
0

我已经添加了一个imageview,我试图在它上面添加一个按钮。怎么做。添加一个UIImageView和一个按钮

self.imgview = [UIImageView alloc]initWithImage:[UIImage imageNamed:@"f.png"]]; 
[self.imgview addSubView:button]; 

[self.view addSubView:imgView]; 

什么,我得到的是f.png形象,我没有看到,我加入了它的按钮。我怎么解决这个问题?

我不知道什么是错误的,我一直被困在这个问题几个小时。我需要你的帮助

+0

他们俩添加到另一个视图。 – 2012-02-15 18:24:55

+1

你是否看到按钮,如果你只添加它到self.view而不添加imgView? – sch 2012-02-15 18:36:27

+0

你的答案帮助。 – shajem 2012-02-15 18:53:54

回答

2

您需要设置的意见框架:

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]; 
0
self.imgview = [UIImageView alloc]initWithImage:[UIImage imageNamed:@"f.png"]]; 
[self.view addSubView:imgView]; 
[self.view addSubView:button]; 

只是他们两个添加到视图,添加按钮图像后,使其构成对图像的顶部。假设他们的框架的x,y坐标也匹配起来。

+0

嗯,我试着用界面生成器来做这件事,但我最终遇到了同样的问题。帮帮我 ? – shajem 2012-02-15 18:25:33

+0

我不认为这真的是问题所在。在** shajem **代码中,按钮是图像视图的子视图,因此它不能被图像覆盖。 – sch 2012-02-15 18:35:18

0

尝试使用bringSubviewToFront方法