带有分钟和秒的日期选择器 [英] Date picker with minutes and seconds

查看:96
本文介绍了带有分钟和秒的日期选择器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对Swift还是陌生的,而对编程又是相当陌生的。我正在制作一个基本的倒数计时器应用,并希望使用日期选择器选择倒数的持续时间。我有一个标签,它是一个timeMin变量和一个timeSec变量的串联,以:字符串分隔。

I'm new to Swift and fairly new to programming in general. I'm making a basic countdown timer app and want to use a date picker to select the duration of the countdown. I have a label which is a concatenation of a timeMin variable and a timeSec variable, seperated by a ":" string.

当日期选择器的模式设置为倒数计时器时,它只能做几个小时和几分钟。有什么办法可以将其更改为分钟和几秒钟?日期选择器上显示的文本也应该是分钟和秒,而不是小时和分钟。

When the date picker's mode is set to countdown timer, it can only do hours and minutes. Is there any way I could change this to minutes and seconds? The text displayed on the date picker should be minutes and seconds too, rather than hours and minutes.

因此,如果我的标签从02:00开始,请使用日期选择器并选择4分(分钟)和35分(秒)应该只会导致标签更改为04:35。

So if my label starts off as 02:00, using the date picker and selecting 4 in minutes and 35 in seconds should simply result in the label changing to 04:35.

感谢您抽出宝贵的时间来提供帮助。

Thanks for taking the time to help.

推荐答案

使用 UIDatePicker 是不可能的,如果要实现此功能,则必须使用 UIPickerView 创建自定义日期选择器。您必须在 UIPickerView 中使用2个组件,一个组件用于分钟,一个组件用于秒。并从 UIPickerViewDatasource titleForRow:... 方法提供值(具有适当的间隔)。

This is not possible with UIDatePicker, If you want to implement this, then you have to create custom datepicker by using UIPickerView. You have to take 2 components in UIPickerView, one for minutes and one for seconds. And supply the values(with appropriate interval) from titleForRow: ... method of UIPickerViewDatasource.

这篇关于带有分钟和秒的日期选择器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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