Is it possible to install UIDatePicker only for a few days (excluding hours, minutes and seconds)?

I am trying to get UIDatePicker to provide the user with only date, month and year. I want to avoid representing them in hours, minutes and seconds, as this happens by default. I tried to find something that might help, but might find solutions that are not explained clearly in Objective-C, however I am coding in Swift. Any ideas? Thanks in advance!

-2
source share
3 answers

you need to select a date selection mode

@IBOutlet weak var myDatePicker: UIDatePicker! override func viewDidLoad() { super.viewDidLoad() myDatePicker.datePickerMode = .date // or .Date (Swift 2.x) } 

date selection options .

SWIFT Declaration

 var datePickerMode: UIDatePickerMode 

Discussion The value of this property indicates the date selection mode. This determines whether the date picker allows you to select a date, time, both a date and time, or a countdown time. The default mode is UIDatePickerModeDateAndTime. See Date Selection Mode for a list of constant modes.

UIDatePickerMode

Date selection mode.

declaration constants

Time

Date selection displays hours, minutes, and (optionally) AM / PM. The exact items shown and their order depend on the set of locales. An example of this mode is [6 | 53 | PM].

Available in iOS 2.0 and later.

the date

Date selection shows months, days of the month, and years. The exact order of these elements depends on the locale setting. An example of this mode is [November | 15 | 2007].

Available in iOS 2.0 and later.

DateAndTime

Date selection displays dates (as a single day of the week, month, and day of the month) plus hours, minutes, and (optionally) AM / PM. The exact order and format of these elements depends on the set of locales. An example of this mode is [Wed Nov 15 | 6 | 53 | PM].

Available in iOS 2.0 and later.

CountDownTimer

Selecting a date displays the hours and minutes, for example [1 | 53]. The application should set a timer for firing at the appropriate interval and set the date selection when mark seconds.

Available in iOS 2.0 and later.

+2
source

If you use storyboards, just change the mode to β€œdate” in the attribute inspector.

+2
source
 YourPickerView.datePickerMode=UIDatePickerModeDate; 
0
source

Source: https://habr.com/ru/post/980647/


All Articles