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?
Asked
Active
Viewed 1,640 times
0
-
First clear your question. – iPatel Mar 19 '14 at 05:58
-
it is useful for you.. http://stackoverflow.com/questions/11197855/iphone-display-date-picker-on-textfield-click – Rushi trivedi Mar 19 '14 at 06:43
-
I did edit the explanation. Please check – lay55 Mar 21 '14 at 04:31
3 Answers
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)
};
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