星期几多选UI

时间:2016-05-28 15:52:07

标签: ios swift enums datepicker

我正在创建一个活动应用,需要允许用户选择星期几,即。周一,周二,各种各样,等等,如果他们想要创造一个重复的事件。

是否有库/枚举或功能允许此预选已预先构建? (就像datePicker已经构建了UI一样?)

1 个答案:

答案 0 :(得分:2)

Picker Views

在界面构建器中添加它,连接delegatedata 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.
}