Posts

Post not yet marked as solved
10 Replies
766 Views
Hi,I am trying to call on number located on a label.When i double tap on it, it should call the numberI have 3 label with 3 different numberI can get the one i touch by view.addGestureRecognizer(longPressGesture) but the objc function doesnt want argument so i cant pass my call with the one i touch.in both my function, i force label 2 (lbl2) for testing but i would like to have the one i double tap?How can i do that?ThanksThis is my code: @IBOutlet weak var lbl2: UILabel!@IBOutlet weak var lbl3: UILabel!@IBOutlet weak var lbl4: UILabel!@IBOutlet weak var pvemergency: UIPickerView! override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view. pvemergency.dataSource = self pvemergency.delegate = self lbl2.isUserInteractionEnabled = true lbl3.isUserInteractionEnabled = true lbl4.isUserInteractionEnabled = true let longPressGesture = UILongPressGestureRecognizer(target: self, action: #selector(self.longPress)) view.addGestureRecognizer(longPressGesture) longPressGesture.minimumPressDuration = 2.0 let doubleTapGesture = UITapGestureRecognizer(target: self, action: #selector(self.doubleTap))lbl2.addGestureRecognizer(doubleTapGesture) doubleTapGesture.numberOfTapsRequired = 2 } @objc func longPress(){ UIPasteboard.general.string = lbl2.text } @objc func doubleTap (){ let phone = String(lbl2.text?) callNumber(phonenumber: phone) } func callNumber (phonenumber:String) { if let phoneCallURL = URL(string: "tel://\(phonenumber)"){ let application:UIApplication = UIApplication.shared if (application.canOpenURL(phoneCallURL)) { application.open(phoneCallURL,options: [:], completionHandler: nil) }}
Posted
by vanvan.
Last updated
.