我想知道如何在swift
中将间隔值添加到UIDateTimePicker
8am-8:30am
8:30am-9am
9am-9:30am
9:30am-10am
10am-10:30am
10:30am-11am
答案 0 :(得分:1)
你可以尝试这样的事情。在UIPickerView
或xib
storyboard
之后添加一个viewController
,然后将delegate
和datasoucre
设置为UIPickerView
viewController
。现在创建一个这样的字符串数组。
var timeArr: [String] = [String]()
现在在viewDidLoad
中初始化此数组
override func viewDidLoad() {
super.viewDidLoad()
self.timeArr = ["8:00AM - 8:30AM", "8:30AM - 9:00AM", "9:00AM - 9:30AM", "9:30AM - 10:00AM"]
}
现在在您的delegate
中添加datasource
和UIPicker
ViewController
方法
func numberOfComponentsInPickerView(pickerView: UIPickerView) -> Int {
return 1
}
func pickerView(pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
return self.timeArr.count
}
func pickerView(pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
return self.timeArr[row]
}
func pickerView(pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
print(self.timeArr[row])
}
这将创建您想要选择时间的Picker。