当我将日期选择器放在控制器的顶部栏以及工具栏时,为了清晰起见,节省了视图控制器上的空间。
但是,我应该怎么做,以便选择器视图在按钮点击时显示工具栏,并在按钮点击时消失。
有人可以帮我解决这个问题吗?
答案 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