I have a view with UITapGestureRecognizer
I want to show uidatepicker, when I tap on view
How can I do it ?
thanks in advance
I have a view with UITapGestureRecognizer
I want to show uidatepicker, when I tap on view
How can I do it ?
thanks in advance
I'm not sure exactly what you want, but if you just have something like this?
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var datePicker: UIDatePicker!
@IBAction func viewTapped(sender: Any) { // link gesture recogniser here
datePicker.isHidden = false
}
override func viewDidLoad() {
datePicker.isHidden = true // or set hidden checkbox to true in the picker's attributes inspector
}
}
Just declare your picker datasource inside the touch action.
// in viewDidload method
let gesture = UITapGestureRecognizer(target: self, action: #selector (self.touchAction (_:)))
self.view.addGestureRecognizer(gesture) // could be your custom view also
// for Swift 3
func touchAction(_ sender:UITapGestureRecognizer){
// datasource
self.pickerData = ["data1","data2" .. ect]
if pickerData != nil{
self.picker.delegate = self
self.picker.dataSource = self
}
}
Note: your controller class should confirm UIPickerViewDelegate, UIPickerViewDataSource
in order to use picker delegates.