[重新措辞]
嗨
我原来的问题还不够清楚-让我改一下。
在iOS的“联系人”应用中输入周年纪念日时,我看到年份为“ ----”(请参见图片)。
我以为是UIDatepicker,但找不到方法。.
(我检查了开发人员文档,但没有办法)。
请帮助我做到这一点!谢谢!
[原问题]
我试图弄清楚该UIDatePicker的“年份”如何设置为“周年”-来自iOS联系人应用。
我检查了开发人员documentation的UIDatePicker,但找不到任何有关它的信息。
有谁知道?
答案 0 :(得分:0)
感谢狮子座!
我不知道UIpickerview真是可耻..
我可以用年份“ ----”创建UIPickerView。
let monthArray = [......]
let dayArray = [......]
let yearArray = ["2016", "2017", "2018", "----", "2019", "2020", "2021"]
func numberOfComponents(in pickerView: UIPickerView) -> Int {
return 3
}
func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
switch component {
case 0:
return self.monthArray.count
case 1:
return self.dayArray.count
case 2:
return self.yearArray.count
default:
print ("do nothing")
}
}
func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
switch component {
case 0:
return monthArray[row]
case 1:
return dayArray[row]
case 2:
return yearArray[row]
default:
print ("do nothing")
}
return nil
}
func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
let monthSelected = self.monthArray[pickerView.selectedRow(inComponent: 0)]
let daySelected = self.dayArray[pickerView.selectedRow(inComponent: 1)]
let yearSelected = self.yearArray[pickerView.selectedRow(inComponent: 2)]
self.daySelectedLabel.text = monthSelected + " " + daySelected + ", " + yearSelected
}