Skip to content

Date Time Picker

levching edited this page Apr 15, 2020 · 4 revisions

You can use native IOS Date Time Picker when you want your player to pick a date, time or delay. Available picker options are listed inside the ISN_UIDateTimePickerMode enum.

The following code snippet demonstrates how to show a date picker:

using SA.iOS.UIKit;
...
ISN_UIDateTimePicker picker = new ISN_UIDateTimePicker();
picker.Show((DateTime date) => {
    ISN_Logger.Log("User picked date: " + date.ToLongDateString());
});

You may also choose DateTime picker mode, the available modes are:

namespace SA.iOS.UIKit {
    /// <summary>
    /// The mode displayed by the date picker.
    /// </summary>
    public enum ISN_UIDateTimePickerMode  {
        /// <summary>
        /// Displays hour, minute, and optionally AM/PM designation 
        /// depending on the locale setting (e.g. 6 | 53 | PM)
        /// </summary>
        Time = 1,

        /// <summary>
        /// Displays month, day, and year 
        /// depending on the locale setting (e.g. November | 15 | 2007)
        /// </summary>
        Date = 2,

        /// <summary>
        /// Displays date, hour, minute, and optionally AM/PM designation 
        /// depending on the locale setting (e.g. Wed Nov 15 | 6 | 53 | PM)
        /// </summary>
        DateAndTime = 3,

        /// <summary>
        /// Displays hour and minute (e.g. 1 | 53)
        /// </summary>
        CountdownTimer = 4  
    }
}

Once you choose the mode, you can also customize the appearance of date time picker. Using the following properties.

MinuteInterval - Use this property to set the interval displayed by the minute's wheel (for example, 15 minutes). The interval value must be evenly divided into 60; if it is not, the default value is used. The default and minimum values are 1; the maximum value is 30.

SetDate - Sets the date to display in the date picker.

Here are more code samples for you.

Time Picker

The time picker with starting time -20h from the current time, and with 30 min interval:

using SA.iOS.UIKit;
...

DateTime starDate = DateTime.Now;
starDate =  starDate.AddHours(-20);

ISN_UIDateTimePicker picker = new ISN_UIDateTimePicker();
picker.SetDate(starDate);
picker.DatePickerMode = ISN_UIDateTimePickerMode.Time;
picker.MinuteInterval = 30;

picker.Show((DateTime date) => {
    ISN_Logger.Log("User picked date: " + date.ToLongDateString());
});

Date Picker

The date picker, with start date - 20days from the current date:

using SA.iOS.UIKit;
...

DateTime starDate = DateTime.Now;
starDate = starDate.AddDays(-20);

ISN_UIDateTimePicker picker = new ISN_UIDateTimePicker();
picker.SetDate(starDate);
picker.DatePickerMode = ISN_UIDateTimePickerMode.Date;

picker.Show((DateTime date) => {
    ISN_Logger.Log("User picked date: " + date.ToLongDateString());
});

Countdown Timer

The Countdown Timer with 10 minutes interval, that will have countdown timer initial value 5h 40min.

using SA.iOS.UIKit;
...

ISN_UIDateTimePicker picker = new ISN_UIDateTimePicker();     
picker.DatePickerMode = ISN_UIDateTimePickerMode.CountdownTimer;
picker.MinuteInterval = 10;

//Set countdown start duration
int hours = 5;
int minutes = 20;
int seconds = 0;
TimeSpan span = new TimeSpan(hours, minutes, seconds);
picker.SetCountDownDuration(span);

picker.Show((DateTime date) => {
    ISN_Logger.Log("User picked date: " + date.ToLongDateString());
});

In case you want to track intermediate values while a user is picking a date you may subscribe to OnPickerDateChanged event

See the example below:

ISN_UIDateTimePicker.OnPickerDateChanged.AddListener((DateTime date) => {
    Debug.Log("User chnaged a date to: " + date.ToLongDateString());
});

About

Foundation

AV Foundation

App Tracking Transparency

Game Kit

Store Kit

UI Kit

Social

Replay Kit

Contacts

AVKit

Photos

App Delegate

User Notifications

MediaPlayer

Core Location

AdSupport

EventKit

CloudKit

Authentication Services

XCode

Knowledge Base

Clone this wiki locally