我试图设置UIDatePicker只提出时间.按下文本字段时,DatePicker会通过操作启动.我没有使用DatePicker Viewer.任何帮助表示赞赏.谢谢
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) }
Marcelo.. 13
尝试设置其模式:
starttimedatePicker.datePickerMode = UIDatePickerMode.Time
technerd.. 6
这可能对您有帮助。
let starttimedatePicker = UIDatePicker() starttimedatePicker.datePickerMode = UIDatePickerMode.Time startTimeDiveTextField.inputView = starttimedatePicker starttimedatePicker.addTarget(self, action: #selector(ViewController.startTimeDiveChanged), forControlEvents: .ValueChanged) func startTimeDiveChanged(sender: UIDatePicker) { let formatter = NSDateFormatter() formatter.timeStyle = .ShortStyle startTimeDiveTextField.text = formatter.stringFromDate(sender.date) }
如果您在Storyboard或Xib中使用DatePicker,则进行如下设置。
尝试设置其模式:
starttimedatePicker.datePickerMode = UIDatePickerMode.Time
这可能对您有帮助。
let starttimedatePicker = UIDatePicker() starttimedatePicker.datePickerMode = UIDatePickerMode.Time startTimeDiveTextField.inputView = starttimedatePicker starttimedatePicker.addTarget(self, action: #selector(ViewController.startTimeDiveChanged), forControlEvents: .ValueChanged) func startTimeDiveChanged(sender: UIDatePicker) { let formatter = NSDateFormatter() formatter.timeStyle = .ShortStyle startTimeDiveTextField.text = formatter.stringFromDate(sender.date) }
如果您在Storyboard或Xib中使用DatePicker,则进行如下设置。