Open UIDatePicker programmatically in iOS 14(在 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 iOS 14 中以编程方式打开 UIDatePicker
基础教程推荐
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01