Scubadivingfool Scubadivingfool - 10 months ago 93
Swift Question

Trying to set only time in UIDatePicker in Swift 2.0

I am trying to set the UIDatePicker to come up with the time only. The DatePicker comes up through an action when the textfield is pressed. I have not used the DatePicker Viewer. Any help is appreciated. Thanks

let starttimedatePicker = UIDatePicker()
startTimeDiveTextField.inputView = starttimedatePicker
starttimedatePicker.addTarget(self, action: "startTimeDiveChanged:", forControlEvents: .ValueChanged)

func startTimeDiveChanged(sender: UIDatePicker) {
let formatter = NSDateFormatter()
formatter.timeStyle = .ShortStyle
startTimeDiveTextField.text = formatter.stringFromDate(


Try setting its Mode:

starttimedatePicker.datePickerMode = UIDatePickerMode.Time