答案 0 :(得分:-1)
func configureDatePicker(){
let datePicker = UIPickerView.init()
// datePicker.datePickerMode = .Date
datePicker.delegate = self
datePicker.dataSource = self
txtDOB.inputView = datePicker
noteToolbar = UIToolbar.init(frame: CGRectMake(0, 0, self.view.frame.size.width, 44))
let btnDone = UIBarButtonItem.init(title: "Done", style: .Done, target: self, action: #selector(AboutYouViewController.datePicked))
let btnCancel = UIBarButtonItem.init(title: "Cancel", style: .Done, target: self, action: #selector(AboutYouViewController.dismissKeyboard))
let flexibleButton = UIBarButtonItem.init(barButtonSystemItem: .FlexibleSpace, target: self, action: nil)
noteToolbar.items = [btnDone, flexibleButton, btnCancel]
txtDOB.inputAccessoryView = noteToolbar
}
func numberOfComponentsInPickerView( pickerView: UIPickerView) -> Int
{
return 1
}
func pickerView(pickerView: UIPickerView,
numberOfRowsInComponent component: Int) -> Int
{
return 3
}
func pickerView(_pickerView: UIPickerView,
titleForRow row: Int,
forComponent component: Int) -> String?
{
return "Test"
}
您可以根据自己的要求进行修改,并可以使用pickerview的dalagate和datasource mehtods。它与UITableView委托和数据源一样易于使用