Shivam Sharma M Shivam Sharma M - 3 years ago 226
Swift Question

Swift open datepicker at bottom with done and cancel button when i click label

I am making application in iphone using swift and following code

override func viewDidLoad() {
dateSet.userInteractionEnabled = true
let aSelector : Selector = "lblTapped"
let tapGesture = UITapGestureRecognizer(target: self, action: aSelector)
tapGesture.numberOfTapsRequired = 1


func lblTapped(){
// need to add datapicker UIView

Answer Source

Use textfield inputView for datepicker to display at bottom. Sample code below

private func dateTextFieldSetup()

        let datePickerView  : UIDatePicker = UIDatePicker()
    datePickerView.datePickerMode = UIDatePickerMode.Date
    sampleTextfield.inputView = datePickerView
    datePickerView.addTarget(self, action:#selector(CFTextField.handleDatePickerForSlectedText(_:)), forControlEvents: UIControlEvents.ValueChanged)


For UILabel inputView property is not available.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download