【发布时间】:2011-12-16 12:32:32
【问题描述】:
我想创建一个 UIButton 来显示在 UIImageView 上。我的代码sn-p如下图:
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];
我的应用程序在我想要的部分图像上准确显示按钮,但它不响应单击图像。相反,它确实检测到单击,因为我在其检测中记录输出。但我希望这个按钮能够点击选择并执行一些功能。
提前致谢。
瓦希布
【问题讨论】:
标签: iphone ios ipad uiimageview uibutton