如何在图像视图上方放置自定义按钮>

时间:2011-04-26 05:35:58

标签: objective-c xcode

我想在图像视图上方放置一个自定义按钮,但这样做会使按钮消失。我在Interface Builder中做了所有这些。是否有任何技巧可以使图像视图上方的按钮可见?

3 个答案:

答案 0 :(得分:2)

在界面构建器中使用bringtofront。首先选择所需的按钮,然后在布局菜单中使用前置。这是一个截图

BringToFront

答案 1 :(得分: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];

答案 2 :(得分: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];