UIButton 作为 UILabel 中的子视图
我正在尝试动态添加 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
有趣的是,我在发布这个问题 5 分钟后就得到了自己的答案。看来我必须在标签上启用我的 userInteraction 。
IE -
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. -
你的问题(以及随后的答案)并没有说明你正在尝试做的事情是否明智(或缺乏智慧)。
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 aUIButton
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.