Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add target to UITextView and UILabel in swift

Tags:

ios

swift

I have a UITable and I have multiple labels and textviews in it. I want a method to be called when touchupinside event is triggered . I used targetForAction but i cannot specify touchUpInside event in it.And the textview is not editable

On a whole , i want what a button does with addTarget to be done by textview and label. Please help me

like image 982
Prashanth Narasimha Avatar asked May 26 '16 12:05

Prashanth Narasimha


1 Answers

add Gesture and try

let tap = UITapGestureRecognizer(target: self, action: #selector(self.doubleTapped(_:)))
    tap.numberOfTapsRequired = 1
     yourlabel.tag = indexPath.row
    yourlabel.isUserInteractionEnabled = true
    yourlabel.addGestureRecognizer(tap)

call method like

func doubleTapped(_ recognizer: UITapGestureRecognizer) {

        print(recognizer.view!.tag)

}

for textview

add yourTextView.delegate = self

func textViewDidChange(_ textView: UITextView) {
    //do continue your work
}

You can view other such methods here.

like image 115
Anbu.Karthik Avatar answered Sep 30 '22 18:09

Anbu.Karthik