2011-04-26 120 views
1

我想在图像视图上放置自定义按钮,但这样做会使按钮消失。我在Interface Builder中做了所有这些。有没有什么窍门可以在图片视图上方看到按钮?如何在图像视图上放置自定义按钮>

+0

我可以知道为什么要添加图片视图上方的按钮吗? – Aravindhan 2011-04-26 05:41:48

+0

它的喜欢dis ...我有四个标签栏..我的最后一个标签有一个imageview覆盖整个屏幕,我想放置在图像视图上方的4个按钮....但在图像视图上方添加按钮使得按钮不可见...是否可能 – kingston 2011-04-26 05:54:38

回答

1

创建ImageView的编程和设置帧。之后,也编程方式创建uibutton,并将该按钮放在imageview的子视图中。确保使您的imageview属性Userinteraction Enabled为TRUE。

例如,

UIImageView *img1 = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"screen.png"]]; 
img1.frame = CGRectMake(50, 70, 100, 50); 
[img1 setUserInteractionEnabled:TRUE]; 
[self.view addSubview:img1]; 

UIButton *btn1 = [[UIButton alloc]initWithFrame:CGRectMake(10, 10, 80, 50)]; 
btn1 = [UIButton buttonWithType:UIButtonTypeCustom]; 
[btn1 addTarget:self action:@selector(aMethod:) forControlEvents:UIControlEventTouchUpInside]; 
[btn1 setTitle:@"Show View" forState:UIControlStateNormal]; 
[img1 addSubview:btn1]; 
1

我不太了解Interface Builder。如果你试图以编程方式添加这些,意味着它会起作用。
对于编程

IBOutlet UIImageView *image; 
    UIImage *image1=[UIImage imageNamed:@name.jpg"]; 
    image=[[UIImageview alloc]initWithImage:image1]; 
    image.frame=CGRectMake(0,0,320,400); 
    [self.view addSubview:image]; 
    [image release];   

添加图像对于在界面生成器编程添加按钮

UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
[button addTarget:self 
      action:@selector(aMethod:) 
forControlEvents:UIControlEventTouchDown]; 
[button setTitle:@"Show View" forState:UIControlStateNormal]; 
button.frame = CGRectMake(80.0, 210.0, 160.0, 40.0); 
[self.view addSubview:button]; 
1

使用bringtofront。首先选择您想要的按钮,然后在布局菜单中使用前面的按钮。下面是截图

BringToFront

+0

谢谢你的工作 – kingston 2011-04-26 06:14:39