我正在创建一个活动应用,需要允许用户选择星期几,即。周一,周二,各种各样,等等,如果他们想要创造一个重复的事件。
是否有库/枚举或功能允许此预选已预先构建? (就像datePicker已经构建了UI一样?)
答案 0 :(得分:2)
在界面构建器中添加它,连接delegate
和data source
,并将以下代码添加到UIViewController
。
let pickerData = NSCalendar.currentCalendar().shortWeekdaySymbols
func numberOfComponentsInPickerView(pickerView: UIPickerView) -> Int {
return 1
}
func pickerView(pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
return pickerData.count
}
func pickerView(pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
return pickerData[row]
}
func pickerView(pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
// Your code here.
}