我想创建一个UIButton以在UIImageView上显示。我的代码片段如下:
imageView = [[UIImageView alloc] initWithImage:image]; //initWithImage:image
imageView.userInteractionEnabled = YES; //to enable touch interaction with image
UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[btn setTitle:@"ClickMe" forState:UIControlStateNormal];
[btn.titleLabel setFont:[UIFont systemFontOfSize:16]];
btn.frame = CGRectMake(340, 550, 70, 50);
[btn addTarget:self action:@selector(onClickHotSpotButton) forControlEvents:UIControlEventTouchUpInside]; //it wasnt working
[imageView addSubview:btn];
[self addSubview:imageView];
我的应用程序在我想要的图像部分精确显示按钮,但它无法响应点击图像。相反,它会检测到单击并将其输出到日志中。但我希望这个按钮在选择时能够被点击并执行一些功能。
提前感谢。
wahib