Search code examples
iosswiftuidatepicker

UIDatePicker components not scrolling properly and sometimes moves outside of the view


UIDatePicker components not scrolling properly and sometimes moves outside of the view.

Tried with adding date picker programatically as well as using storyboards.

I am assigning date picker as textField's input view. And textField is in table view cell. Code

func assignDatePickerTo(textField: UITextField) { 
    let datePicker = UIDatePicker() 
    datePicker.datePickerMode = UIDatePickerMode.date 
    let currentDate = Date() 
    datePicker.minimumDate = currentDate      
    datePicker.setDate(currentDate, animated: false) 
    datePicker.backgroundColor = UIColor.white     
     datePicker.addTarget(self, action: #selector(self.neededFromDateChanged(sender:)), for: UIControlEvents.valueChanged) 

    textField.inputView = datePicker 
}

UI Screenshot below

enter image description here


Solution

  • The problem was due to some other third party library in which they have written the category on scrollView to updateContentSize when scrollView updates constraints which is getting called when I scroll datePicker.