如何在按钮单击时显示日期选择器,因为日期选择器位于视图控制器的顶部栏中

时间:2017-02-07 04:21:52

标签: ios swift uidatepicker

当我将日期选择器放在控制器的顶部栏以及工具栏时,为了清晰起见,节省了视图控制器上的空间。

但是,我应该怎么做,以便选择器视图在按钮点击时显示工具栏,并在按钮点击时消失。

有关详细信息,请参阅下面提到的图像。 enter image description here

有人可以帮我解决这个问题吗?

2 个答案:

答案 0 :(得分:0)

func createDatePicker() {

    self.datepicker.frame = CGRect(x: 0, y: 400, width:self.view.frame.size.width, height: 200)
    self.view.addSubview(datepicker)
}

@IBAction func buttonclicked() {
    self.createDatePicker()
}

答案 1 :(得分:-1)

你可以在textfield上使用datepicker,因为text字段有一个默认属性inputAccessoryView所以使用我的代码:

txtFieldCustom.inputView = datePicker           //To make appearence of date picker
txtFieldCustom.inputAccessoryView = toolBar     //To make appearence of toolbar