iOS Swift 3 - UIDatePicker -
i have uidatepicker
shows day, month , year. don't know how parameters.
so best way day, month , year uidatepicker
using swift 3?
in swift 3 can use datecomponents
way.
first add action on datepicker
.valuechanged
events.
datepicker.addtarget(self, action: #selector(datechanged(_:)), for: .valuechanged)
then selected day, month , year using datecomponents
in action.
func datechanged(_ sender: uidatepicker) { let componenets = calendar.current.datecomponents([.year, .month, .day], from: sender.date) if let day = componenets.day, let month = componenets.month, let year = componenets.year { print("\(day) \(month) \(year)") } }
Comments
Post a Comment