使 UILabel 可触摸

Making UILabel touchable(使 UILabel 可触摸)

本文介绍了使 UILabel 可触摸的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 UILabel,我想让它对触摸做出反应.我尝试在标签顶部放置一个按钮,因此我可以与按钮进行交互.但是,按钮不能完全透明,对吧?我可以将按钮的 alpha 设置为 0,02,但它仍然在背景中可见.如何解决这个问题?也许我可以以其他方式设置属性以使它们完全不可见?还是有其他解决办法?

I have a UILabel and I would like to make it react to a touch. I tried putting a button on top of the label, thanks to this I could interact with the button. However, the button cannot be fully transparent, right? I could set an alpha of the button to 0,02, but it is still visible on by background. How to solve this? Maybe I could set the properties in some other way to make them fully invisible? Or is there some other solution?

推荐答案

首先,为什么不直接使用一个按钮并将按钮标题设置为标签的内容?

First, why not just use a button and set the button title to the label's contents?

如果您不能/不想这样做,您也可以在标签上设置 userInteractionEnabled = YES,然后在标签上添加手势识别器.

If you can't/don't want to do that, you can also set userInteractionEnabled = YES on the label and then add a gesture recognizer to the label.

这篇关于使 UILabel 可触摸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:使 UILabel 可触摸