2016-08-01 22 views

答えて

0
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のメソッドを使用できます。 UITableViewデリゲートとデータソースと同じように使いやすい

関連する問題