Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
467 views
in Technique[技术] by (71.8m points)

ios - 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(sender.date)
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Try setting its Mode:

starttimedatePicker.datePickerMode = UIDatePickerMode.Time

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...