Date picker in swift
let datepicker = UIDatePicker()
func CreateDatePicker()
{
datepicker.datePickerMode = .date
UserDOB.inputView = datepicker
let toolbar = UIToolbar()
toolbar.sizeToFit()
let doneButton = UIBarButtonItem(barButtonSystemItem:.done,target:nil,action:#selector(doneProcess))
doneButton.setTitleTextAttributes([NSAttributedStringKey.foregroundColor : UIColor(rgb: 0xC5949E)], for: .normal)
toolbar.setItems([doneButton], animated: false)
UserDOB.inputAccessoryView = toolbar
}
// date pickr done button
@objc func doneProcess()
{
let dateformatter = DateFormatter()
dateformatter.dateStyle = .medium
dateformatter.timeStyle = .none
dateformatter.dateFormat = "dd-MM-yyyy"
UserDOB.text = dateformatter.string(from: datepicker.date)
self.view.endEditing(true)
}
Comments
Post a Comment