Nejc Kasagic February 2016

How to only display the time in UIDatePicker?

I need to change the code so that we will only display the time in UIDatePicker.

func textFieldDidBeginEditing(textField: UITextField) {
    if textField == TextfieldDataSelection {
        let datePicker = UIDatePicker ()
        textField.inputView = datePicker
        datePicker.addTarget(self, action: "datePickerChanged:", forControlEvents: .ValueChanged)
        }
    if textField == TextfieldDeadline {
        let datePicker = UIDatePicker ()
        textField.inputView = datePicker
        datePicker.addTarget(self, action: "date1PickerChanged:", forControlEvents: .ValueChanged)
    }
    }
func datePickerChanged(sender:UIDatePicker) {
    let formatter = NSDateFormatter()
    formatter.dateStyle = .MediumStyle
    TextfieldDataSelection.text = formatter.stringFromDate(sender.date)
}
func date1PickerChanged(sender:UIDatePicker) {
    let formatter = NSDateFormatter()
    formatter.dateFormat = "MMM dd, yyyy hh:mm a"
    TextfieldDeadline.text = formatter.stringFromDate(sender.date)

Answers


UditS February 2016

You need to set datePickerMode property of UIDatePicker to Time

var datePicker = UIDatePicker()
datePicker.datePickerMode = .Time


UlyssesR February 2016

Set

datePicker.datePickerMode = UIDatePickerMode.Time

Post Status

Asked in February 2016
Viewed 1,538 times
Voted 4
Answered 2 times

Search




Leave an answer