简体   繁体   English

以编程方式触发 UIDatePicker 上的点击事件

[英]Programmatically trigger a click event on UIDatePicker

I want to have a hidden datepicker and trigger a tap event on that UIControl when I tap another UIView.当我点击另一个 UIView 时,我想要一个隐藏的日期选择器并在该 UIControl 上触发一个点击事件。

@objc func editDateTime() {
    self.datePicker.sendActions(for: .touchUpInside)
}

Whether datepicker is hidden or not, I am not seeing date picker opening up.无论日期选择器是否隐藏,我都没有看到日期选择器打开。 Basically I am trying to show a custom UI instead of the standard rendering of date picker.基本上我正在尝试显示自定义 UI 而不是日期选择器的标准呈现。

I'm guessing you want the "popup calendar" feature?我猜你想要“弹出日历”功能?

If so, you can overlay a button (or label, or view, or whatever) on the Compact Date Picker, and allow a tap to pass-through to the trigger the calendar popup.如果是这样,您可以在紧凑型日期选择器上覆盖一个按钮(或 label,或视图,或其他),并允许点击以触发日历弹出窗口。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM