I've got a view controller with different textfields, two of which are for dates. I'm trying to make a date picker appear when the user taps in the text field, for ease of use. For some reason, the date picker looks like this:
I don't know why the image is so big on stack overflow lol
Here is my code:
func createDatePicker() {
// toolbar
let toolbar = UIToolbar()
toolbar.delegate = self
toolbar.sizeToFit()
// bar button
// let doneBtn = UIBarButtonItem(barButtonSystemItem: .done, target: nil, action: nil)
// assign toolbar to textviews
lossDateTextField.inputAccessoryView = toolbar
dateTakenTextField.inputAccessoryView = toolbar
// assign date picker to textfields
lossDateTextField.inputView = datePicker
dateTakenTextField.inputView = datePicker
}
I set the text field delegate to self in viewDidLoad and call the createDatePicker function there as well.
Why is it appearing like this instead of how it's supposed to?
Note: I am using IQKeyboardManagerSwift in the app.
Thanks
Just add bellow code and your date picker will work fine.
if #available(iOS 13.4, *) {
datePicker!.preferredDatePickerStyle = .wheels
}