UIDatePicker to show year only

前端 未结 6 516
时光取名叫无心
时光取名叫无心 2020-12-07 00:51

Is there a way to have a UIDatePicker show year only?

6条回答
  •  借酒劲吻你
    2020-12-07 01:32

    Just updating the existing answer in this post with Swift 3:

    var yearsTillNow : [String] {
        var years = [String]()
        for i in (1970..<2018).reversed() {
            years.append("\(i)")
        }
        return years
    }
    

    Just use this for your UIPickerView datasource.

提交回复
热议问题