如何创建“热点”可以在 Xcode 中的 UIImageView 上单击并触发事件

发布于 2024-10-15 01:22:46 字数 168 浏览 5 评论 0原文

我有一个自定义图形,用作 UIView 的背景。在此图像上有一些文本,我想在其周围创建可点击的热点。例如,一个说“下一个”,一个说“上一个”,我希望这些成为可点击的热点,我可以捕获事件并使用一些数据更改 UITextView。到目前为止,我无法找到有关在 UIImageView 上定义可点击区域的任何帮助。感谢您的帮助!

I have a custom graphic that I am using as the background to a UIView. On this image there are some text that I would like to create clickable hotspots around. For instance, one says "Next" and one says "Previous", I'd like these to be clickable hotspots that I can capture the event and change a UITextView with some data. So far I have been unable to find any help on defining clickable regions on a UIImageView. Thanks for the help!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

好倦 2024-10-22 01:22:46

我只是创建不可见的 UIButtons 来覆盖您想要可点击的区域。在 Interface Builder 中,只需创建按钮并将其类型设置为自定义,并且不提供任何文本或图像。在代码中:

UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(120,30,44,44);
[self.view addSubview:button];  //Here you could add it to the UIImageView instead if you wanted to.  Just make sure interaction is not disabled on the image view
button.tag = 1;
[button addTarget:self action:@selector(clickedHotspot:) forControlEvents:UIControlEventTouchUpInside];

然后使用按钮的标签来确定在 clickedHotspot: 内单击了哪个按钮

I would just create invisible UIButtons that overlay the area you want to be clickable. In Interface Builder, just create the button and set its type to custom and don't provide any text or images. In code:

UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(120,30,44,44);
[self.view addSubview:button];  //Here you could add it to the UIImageView instead if you wanted to.  Just make sure interaction is not disabled on the image view
button.tag = 1;
[button addTarget:self action:@selector(clickedHotspot:) forControlEvents:UIControlEventTouchUpInside];

Then use the button's tag to determine which button was clicked inside of clickedHotspot:

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文