Since UIDatePicker is not available in tvOS, what does one use to ask the user for date/time? Is there a new class that replaces UIDatePicker
?
Thanks
Since Apple does not provide a date picker for tvOS, there is no standard solution.
However, some possible steps would be:
didSet
).Remember that dates and date calculations are complicated(!), so use the provided date concepts and methods - have a look at Calendar and DateComponents
in the documentation.
There, you will find useful methods, for example:
range(of: Calendar.Component, in: Calendar.Component, for: Date)
can be used to find the number of months in a year, days in a month
(and so on).
dateComponents(Set<Calendar.Component>, from: Date)
and date(from:
DateComponents)
can be used to convert from dates to date components
and vice versa.
Further, isValidDate(in: Calendar)
can be useful to check that date
components form a valid date in a certain calendar.
Below is a link to the user interface (with UISegmentedControl
s) that I developed for my app, however, there are other solutions such as the one linked by ergoon.
User interface with segmented controls.
In my case, the date picker is presented modally after selecting a table view cell in an input form.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With