M
M
MarsFM2017-02-11 14:52:59
iOS
MarsFM, 2017-02-11 14:52:59

How to make gesture on UILabel?

Can you suggest, plz
Need to add "Tap" gesture to UIlabel.
If the gesture is added to fieldView, everything works, but it doesn't work on elem1.
What could be the problem?
fieldView - there I draw a field using func draw(_ rect: CGRect) {...}

import UIKit

class ViewController: UIViewController {
    
    var ticTac = TicTacToeModel()
    
    @IBOutlet weak var fieldView: FieldView!

    @IBOutlet weak var elem1: UILabel!  {
        didSet {
            let tapGesture = UITapGestureRecognizer(target: self, action: #selector(self.taplabel))
            elem1.addGestureRecognizer(tapGesture)
        }
    }

    override func viewDidLoad() {
        super.viewDidLoad()
    }
    
    func taplabel() {
        elem1.text = ticTac.stepPlayer()
    }   

}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
iMike, 2017-02-14
@sportredwhite

Ask

elem1.isUserInteractionEnabled = true

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question