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
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];
精彩评论