Making UILabel touchable(使 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 可触摸
基础教程推荐
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- iOS4 创建后台定时器 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
