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 可触摸
				
        
 
            
        基础教程推荐
- 如何比较两个 NSDate:哪个是最近的? 2022-01-01
 - Android Volley - 如何动画图像加载? 2022-01-01
 - SwiftUI-ScrollViewReader的ScrollTo不滚动 2022-01-01
 - Xcode UIView.init(frame:) 只能在主线程中使用 2022-01-01
 - iOS - UINavigationController 添加多个正确的项目? 2022-01-01
 - 为什么姜饼模拟器方向卡在应用程序中? 2022-01-01
 - navigationItem.backBarButtonItem 不工作?为什么上一个菜单仍然显示为按钮? 2022-01-01
 - 如何将图像从一项活动发送到另一项活动? 2022-01-01
 - UIImage 在开始时不适合 UIScrollView 2022-01-01
 - Play 商店的设备兼容性问题 2022-01-01
 
    	
    	
    	
    	
    	
    	
    	
    	
				
				
				
				