سؤال

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