2015-12-10 48 views
1
@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")) 
     } 

一些如何在代码轻击标签时看起来不起作用。UILabel手势响应

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

为什么不使用轻击手势识别器? – Wain

回答

4

我觉得你在添加动作时错过了“:”。

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

我认为你的问题可能是在使用UIGestureRecognizer代替UITapGestureRecogniser

尝试:

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

我不是100%肯定,为什么使用UIGestureRecognizer不起作用,但我自己也遇到了同样的问题,这对我很有帮助。