在 iOS 14 中以编程方式打开 UIDatePicker [英] Open UIDatePicker programmatically in iOS 14

查看:23
本文介绍了在 iOS 14 中以编程方式打开 UIDatePicker的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个普通的UIDatePicker(抱歉不是英文的,请忽略):

I have this normal UIDatePicker (sorry that it's not in English, please ignore that):

但问题是它只在我按下日期选择器时出现:

But the problem is that it only appears when I'm pressing the Date Picker:

我想知道如何在第一张图片中显示日期选择器(它用模糊效果覆盖了所有屏幕)仅使用代码,因此用户不需要按日期选择器显示日期选择器.谢谢.

And I wanted to know how to show the Date Picker like in the first image (that it's covering all the screen with the blur effect) only with code, so the user won't need to press the Date Picker to show the date selector. Thanks.

推荐答案

您可以使用具有 .compact 样式的 datePicker 并在其顶部放置一个 UILabel 并给出它是一种背景颜色,用于将 datePicker 隐藏在其后面,并确保标签用户交互已禁用,然后您应该能够点击 datePicker,它将显示模式,然后更改datePicker 您可以使用自己的日期格式化程序来相应地设置标签的文本,您也可以在 UIView 中同时设置 datePicker 和标签并使其剪辑到边界

You can use a datePicker with .compact style and put a UILabel on top of it and give it a background color to hide the datePicker behind it, and make sure the label user interaction is disabled then you should be able to tap on the datePicker and it will show the modal and then the value changed of the datePicker you can use your own date formatter to set the text of the label accordingly, you might also both the datePicker and the label inside a UIView and make it clip to bounds

这篇关于在 iOS 14 中以编程方式打开 UIDatePicker的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆