문제

I'm want to add button into UIImageView. Added button not active.

UIImageView *iview = [[UIImageView alloc] initWithImage:image];
iview.frame = [[UIScreen mainScreen] applicationFrame];
iview.contentMode = UIViewContentModeTopLeft;

UIButton *bview1 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
bview1.frame = CGRectMake(0, 0, 200, 60);
bview1.center = CGPointMake(100, 100);
[bview1 addTarget:self action:@selector(buttonPress1:) forControlEvents:UIControlEventTouchUpInside];
[bview1 setTitle:@"Image Picker1" forState:UIControlStateNormal];

[iview addSubview:bview1];

[self.view addSubview:iview];

Handler:

- (void)buttonPress1:(id)sender
{
    NSLog(@"1");
}

What's wrong?

도움이 되었습니까?

해결책

Did you try:

iview.userInteractionEnabled = YES;
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top