开发者

How can I place a customized button above an image view> [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. 开发者_运维问答 Closed 10 years ago.

I want to place a customized button above the image view, but doing that makes the button disappear. I'm doing all of this in Interface Builder. Is there any trick to make the button visible above the image view?


use bringtofront in interface builder. First select the button which you want and then use bring to front in layout menu. Here is a screenshot

How can I place a customized button above an image view> [closed]


Create imageview programatically and set the frame. after that create uibutton also programatically and put that button in subview of imageview. Make sure make your imageview property Userinteraction Enabled TRUE.

for e.g.

    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];


I dont know much about Interface Builder. If you try to add both these programatically means it will work.
For adding image programmatically

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];         

For adding button programatically

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];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜