gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 14:10:06 24 4
gpt4 key购买 nike

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

func createDatePickerDgeb1() {

datePickergeb.datePickerMode = .date

let toolbar = UIToolbar()
toolbar.sizeToFit()
let doneButton = UIBarButtonItem(barButtonSystemItem: .done, target: nil, action: #selector(donePressedgeb1))
let spaceButton = UIBarButtonItem(barButtonSystemItem: .flexibleSpace, target: nil, action: nil)
toolbar.setItems([spaceButton,doneButton], animated: false)
gebdatum.inputAccessoryView = toolbar
gebdatum.inputView = datePickergeb

}

选择器 View 显示当前日期。例如,我可以将“01.01.1960”显示为默认值吗?

最佳答案

// 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)

关于ios - 如何在 inputView 中设置默认日期值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52665033/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com