UIButton 作为 UILabel 中的子视图

发布于 2024-08-31 23:11:20 字数 144 浏览 10 评论 0原文

我正在尝试动态添加 UIbutton 作为 UIlable 的子视图。但我无法单击该按钮。该标签似乎不允许发生buttonTapped 事件。
有人可以解释一下这里到底发生了什么吗?有人能给我一个替代方案吗?谢谢!

I am trying to dynamically add a UIbutton as a subview to UIlable. But I am not able to click the button. It seems that the label doesn't allow the buttonTapped event to occur.
Can somebody explain what exactly is happening here? and can anybody give me an alternative for this? thanks!

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

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

发布评论

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

评论(2

混吃等死 2024-09-07 23:11:20

有趣的是,我在发布这个问题 5 分钟后就得到了自己的答案。看来我必须在标签上启用我的 userInteraction 。

IE -

lbl.userInteractionEnabled=YES;

funny, I got answer on my own after 5 mins of posting this question. It seems that I had to enable my userInteraction on the labels.

i.e. -

lbl.userInteractionEnabled=YES;
妳是的陽光 2024-09-07 23:11:20

你的问题(以及随后的答案)并没有说明你正在尝试做的事情是否明智(或缺乏智慧)。 UILabel 对象通常并不意味着是交互式的,并且将 UIButton 放置为标签的子视图,只是因为您可以这样做,听起来根本不像它遵循 Apple HIG for iPhone。

Your question (and subsequent answer) don't speak to the wisdom (or lack thereof) of doing what you're attempting. UILabel objects aren't generally meant to be interactive, and placing a UIButton as a subview to the label, just because you can do it, doesn't sound at all like it's following the Apple HIG for iPhone.

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