ios - UILabel 手势响应

标签 ios swift

@IBOutlet weak var imageTitle: UILabel!
@IBOutlet weak var profileImage: UIImageView!

    func titleStyle(){
    imageTitle.layer.borderWidth = 1.0
            imageTitle.layer.borderColor = UIColor.grayColor().CGColor
            imageTitle.layer.cornerRadius = 10.0

            // Apply Gesture to label
            imageTitle.userInteractionEnabled = true
            imageTitle.tag = 10
            imageTitle.addGestureRecognizer(UIGestureRecognizer(target: self, action: "tappedLabel"))
        }

点击标签时这段代码似乎无法正常工作。

func tappedLabel(gesture: UIGestureRecognizer){
        print("Hi")
    }

最佳答案

我认为您在添加操作时漏掉了“:”。

imageTitle.addGestureRecognizer(UIGestureRecognizer(target: self, action: "tappedLabel:"))

关于ios - UILabel 手势响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34196241/

相关文章:

ios - 使用 openURL 从 Yahoo Mail 客户端发送电子邮件

swift - 在模拟器上测试时的 iPad 设备方向问题

arrays - 从 firebase 中的数组中检索数据

swift - 编辑 SKSpriteNode 自定义类的属性?

ios - 在 UIImageView 中更快地加载大图像

ios - 使用 PFQuery 获取所有 PFUser

macos - 如何在 Swift (MVC) 中引用 Controller

ios - 在 12 小时制设备中使用 Date()

iOS:是否可以要求核心位置框架仅使用蜂窝塔或仅使用 WiFi 或使用 GPS 天线来获取位置?

iphone - 如何将 UIImage 上传到文档中的特定文件夹?