0

Im working on an app where in a single view controller I have a date button and a time button. I want to put one date picker in the view. I want that single date picker to display only date on the date button click and only time on the time button click. How is this possible?

lay55
  • 5
  • 3

3 Answers3

1

Please set your mode using following property as per your requirement :

@property(nonatomic) UIDatePickerMode datePickerMode

Change your mode in your button actions appropriately.

For example, lets say you have UIDatePicker *datePicker;

you can set mode using below code :

datePicker.datePickerMode = UIDatePickerModeTime;
Girish
  • 4,692
  • 4
  • 35
  • 55
Naga Mallesh Maddali
  • 1,005
  • 10
  • 19
0

It's very simple.

There is one property in UIDatePicker:

@property (nonatomic) UIDatePickerMode datePickerMode;

Use this property to change picker type.

Picker type are as follows:

typedef NS_ENUM(NSInteger, UIDatePickerMode) {
    UIDatePickerModeTime,           // Displays hour, minute, and optionally AM/PM designation depending on the locale setting (e.g. 6 | 53 | PM)
    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)
    UIDatePickerModeCountDownTimer, // Displays hour and minute (e.g. 1 | 53)
};
halfer
  • 19,824
  • 17
  • 99
  • 186
P.J
  • 6,547
  • 9
  • 44
  • 74
0

Use either of these approaches.

  • If you are using Storyboard approach, you can simply set the mode to Time.
  • If you are using the code based approach

NSDatePicker *datePicker = [[NSDatePicker alloc] init]; datePicker.datePickerMode = UIDatePickerModeTime; ...

iosCurator
  • 4,356
  • 2
  • 21
  • 25