是否可以将UIDatePicker设置为仅几天(不包括小时,分钟和秒)? [英] Is it possible to set UIDatePicker to only days (exclude hours, minutes and seconds)?

查看:141
本文介绍了是否可以将UIDatePicker设置为仅几天(不包括小时,分钟和秒)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用UIDatePicker只向用户显示日期,月份和年份。我想避免使用默认情况下的小时,分​​钟和秒来呈现它们。我已经尝试过寻找可能有用的东西,但只能找到Objective-C中没有解释清楚的解决方案,但是我在Swift编码。有任何想法吗?提前致谢!

I'm trying to have a UIDatePicker to present only the date, month and year to the user. I want to avoid presenting them with the hours, minutes and seconds like it comes by default. I've tried looking for something that might help but can only find solutions that aren't explained clearly in Objective-C, however I'm coding in Swift. Any ideas? Thanks in advance!

推荐答案

您需要选择日期选择器的模式

you need to chose the mode of the date picker

@IBOutlet weak var myDatePicker: UIDatePicker!

override func viewDidLoad() {
    super.viewDidLoad()
    myDatePicker.datePickerMode = .date // or .Date (Swift 2.x)
}

日期选择器选项


声明SWIFT

Declaration SWIFT



var datePickerMode: UIDatePickerMode




讨论此属性的
值表示日期选择器的模式。
确定日期选择器是否允许选择日期,时间,
日期和时间,或倒计时时间。默认模式是
UIDatePickerModeDateAndTime。请参阅日期选择器模式以获取模式
常量列表。

Discussion The value of this property indicates the mode of a date picker. It determines whether the date picker allows selection of a date, a time, both date and time, or a countdown time. The default mode is UIDatePickerModeDateAndTime. See Date Picker Mode for a list of mode constants.

UIDatePickerMode


日期选择器的模式。

The mode of the date picker.

声明常量

时间

日期选择器显示小时,分钟和(可选)AM / PM指定。显示的确切项目及其顺序取决于区域设置。这种模式的一个例子是[6 | 53 | PM]。

The date picker displays hours, minutes, and (optionally) an AM/PM designation. The exact items shown and their order depend upon the locale set. An example of this mode is [ 6 | 53 | PM ].

在iOS 2.0及更高版本中可用。

Available in iOS 2.0 and later.

日期

日期选择器显示月份,月份和年份。这些项目的确切顺序取决于区域设置。这种模式的一个例子是[11月| 15 | 2007年。

The date picker displays months, days of the month, and years. The exact order of these items depends on the locale setting. An example of this mode is [ November | 15 | 2007 ].

适用于iOS 2.0及更高版本。

Available in iOS 2.0 and later.

DateAndTime

DateAndTime

日期选择器显示日期(作为星期,月和日值的统一日期)加上小时,分钟和(可选)AM / PM指定。这些项目的确切顺序和格式取决于区域设置。这种模式的一个例子是[Wed Nov 15 | 6 | 53 | PM]。

The date picker displays dates (as unified day of the week, month, and day of the month values) plus hours, minutes, and (optionally) an AM/PM designation. The exact order and format of these items depends on the locale set. An example of this mode is [ Wed Nov 15 | 6 | 53 | PM ].

在iOS 2.0及更高版本中可用。

Available in iOS 2.0 and later.

CountDownTimer

CountDownTimer

日期选择器显示小时和分钟值,例如[1 | 53]。应用程序必须将计时器设置为以适当的间隔触发,并将日期选择器设置为秒滴答。

The date picker displays hour and minute values, for example [ 1 | 53 ]. The application must set a timer to fire at the proper interval and set the date picker as the seconds tick down.

在iOS 2.0及更高版本中可用。

Available in iOS 2.0 and later.

这篇关于是否可以将UIDatePicker设置为仅几天(不包括小时,分钟和秒)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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