如何让UIPickerView看起来像图像中的那个?

时间:2016-08-01 09:11:21

标签: ios objective-c uipickerview

我要求制作一个UIPickerView使其看起来像图像中提供的那样。它有5个不同的部分,每个部分有2行。

1 个答案:

答案 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委托和数据源一样易于使用