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
基础教程推荐
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- iOS4 创建后台定时器 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
