How to handle time control in iPhone programming - iphone

Any idea on how to customize the UIDatePicker with single column with list of events in it,and user should be able to select one among it ? Let me know some details about it. or example related to it.
Thank You

In code:
UIDatePicker has the datePickerMode property exactly for this reason.
You can set it with UIDatePickerModeTime.
In Interface Builder:
The top property in Date Picker Attributes window is Mode - choose Time.

You can use any of these
UIDatePickerModeDate, // Displays month, day, and year depending on the locale setting (e.g. November | 15 | 2007)
UIDatePickerModeDateAndTime, // Displays date, hour, minute, and optionally AM/PM designation depending on the locale setting (e.g. Wed Nov 15 | 6 | 53 | PM)
Like this
datePicker.datePickerMode = UIDatePickerModeDateAndTime;

Related

SwiftUI custom DatePicker date label format

I am looking to change the format of the selected date in the label of this SwiftUI DatePicker:
Currently, it is formatted as dd/m/yy + time, but I need it formatted with the name of the month, as dd MMMM yyyy + time (e.g. 30 June 2020 9:00am).
This is how the default calendar app displays it, which is how I want it:
I can't seem to find any methods within DatePicker to be able to do this.
Current code:
DatePicker("Starts", selection: self.$request.startDate.onChange({_ in ...}))
Because I assume you want to use the DatePicker within a Form, I have to say that this is not possible. Because DatePicker doesn't give you access to the actual date Label.
If you use it outside a form you could reference to your date and format it with DateFormatter as you like it to be.

Setting the Count Down Timer in Swift 3

I'm using Date Picker, which is set to Count Down Timer mode. By default it displays the current time. How would I set it to display a specific time on start up? Thanks in advance.
You can use date property
UIDatePicker > date
Use this property to get and set the currently selected date

how to change my date picker show in only month,date ,year, and time

The default UIDatePicker shows both the date and time. I need to show only the month, day, year and time like this
How can I change the date picker to this?
Well First off I suggest reading through the UIDatePicker documentation. Here are the Date Picker Modes:
Date Picker Mode
The mode of the date picker.
typedef enum {
UIDatePickerModeTime,
UIDatePickerModeDate,
UIDatePickerModeDateAndTime,
UIDatePickerModeCountDownTimer
} UIDatePickerMode;
If you cannot find what you need there. Then you can create your own by using a UIPickerView.

Add AM/PM to datepicker?

My UIDatePicker is set to UIDatePickerModeTime but on the apple documentation it says 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 ].. How do i add AM/PM because on my device, those aren't options and it instead uses a 24 hour clock?
This will depend on the settings of the user. If you go to Settings -> General -> Date & Time. there is a "24-Hour" time switch, and based on that users will have the AM/PM indicator on your picker.
Unfortunately UIDatePicker doesn't have an option for that; it always respects the device option of 12-hour or 24-hour time.
If you must have an AM/PM component you may have to go with a custom UIPickerView instead, and build an NSDate out of its components manually.
This thread is somewhat old, but maybe this will be useful to someone else...
As written in the original question, the picker will respect the locale. So, if you what to overrule the system-settings you can set the desired locale on the picker like this:
picker.locale = Locale.init(identifier: "en")
Two things to check,
UIDatePicker has mode which needs to be either set to .time or .dateAndTime in order to support AM/PM format.
set locale to a locale that supports AM/PM, eg "en_US_POSIX", if your locale is set to current, it will read system locale.

UIDatePicker show only month and day

I'd like to have a UIDatePicker where the user can pick a month and a day but not the year. I'm aware that leap years have an extra day, so for simplicity, let's throw that day away.
Is there any way to remove the year column or have 2 reels with month/day that act like the UIDatePicker (grey out days that don't exist in the selected month)?
You cannot use the UIDatePicker class as it stands to do this - The UIDatePicker only supports the following modes
typedef enum {
UIDatePickerModeTime,
UIDatePickerModeDate,
UIDatePickerModeDateAndTime,
UIDatePickerModeCountDownTimer
} UIDatePickerMode;
Create a view and controller that implement the UIPickerViewDelegate and create your own - you may find a little more detail here Fixed labels in the selection bar of a UIPickerView