如何在inputView中设置默认日期值

时间:2018-10-05 11:50:14

标签: ios swift uipickerview

我想在inputView中设置默认日期值。 我有:

InMemoryRepr or Array[Byte]

选择器视图显示了当前日期。例如,我可以默认显示“ 01.01.1960”吗?

1 个答案:

答案 0 :(得分:1)

// Create date components
var dateComponents = DateComponents()
dateComponents.year = 1960
dateComponents.month = 1
dateComponents.day = 1

// Create date from components
let userCalendar = Calendar.current // user calendar
let date = userCalendar.date(from: dateComponents)

// Set datePicker date
datePickergeb.setDate(date, animated: false)