24

In my app i am displaying a UIDateTimePicker in action sheet through code. it is working fine. But i don't want to display date and day.How this can be done. Please help. Thanks in advance.

code:

UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:NSLocalizedString(@"Select     Date",@"Selecte Date")delegate:self cancelButtonTitle:NSLocalizedString(@"Done",@"Done")
destructiveButtonTitle:NSLocalizedString(@"Cancel",@"Cancel")
otherButtonTitles:nil];  


    actionSheet.actionSheetStyle = UIActionSheetStyleBlackTranslucent;
  UIDatePicker  *datePicker = [[UIDatePicker alloc] initWithFrame:CGRectMake(0, 50, 320, 270)];
    //datePicker.showsSelectionIndicator = YES;
//   datePicker.dataSource = self;
//datePicker.delegate = self;
    [actionSheet addSubview:datePicker];
    [datePicker release];

    [actionSheet showInView:self.view];
    [actionSheet setBounds:CGRectMake(0, 0, 320, 500)];
  [actionSheet release];
DShah
  • 9,768
  • 11
  • 71
  • 127
ishhhh
  • 647
  • 2
  • 11
  • 29

4 Answers4

41
datePicker.datePickerMode = UIDatePickerModeTime;
Vaishnavi Naidu
  • 2,625
  • 3
  • 25
  • 26
  • display the datepicker as a subview of UIActionSheet. Then you can use the didDismissWithButtonIndex delegate from UIActionSheetDelegate to dismiss the datepicker – Vaishnavi Naidu Jul 21 '11 at 10:12
7

Set the datePickerMode property to one of the following:

typedef enum {
   UIDatePickerModeTime,
   UIDatePickerModeDate,
   UIDatePickerModeDateAndTime,
   UIDatePickerModeCountDownTimer
} UIDatePickerMode;
Cfr
  • 5,092
  • 1
  • 33
  • 50
Praveen S
  • 10,355
  • 2
  • 43
  • 69
3

In Swift:

datePicker.datePickerMode = UIDatePickerMode.Time
Ever Uribe
  • 639
  • 6
  • 13
2
datePicker.datePickerMode = UIDatePickerModeTime;
Alex Coplan
  • 13,211
  • 19
  • 77
  • 138