how to display only time in UIDatePicker iphone
Asked Answered
E

4

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];
Extortioner answered 21/7, 2011 at 9:32 Comment(0)
T
41
datePicker.datePickerMode = UIDatePickerModeTime;
Tiphane answered 21/7, 2011 at 9:38 Comment(1)
display the datepicker as a subview of UIActionSheet. Then you can use the didDismissWithButtonIndex delegate from UIActionSheetDelegate to dismiss the datepickerTiphane
A
7

Set the datePickerMode property to one of the following:

typedef enum {
   UIDatePickerModeTime,
   UIDatePickerModeDate,
   UIDatePickerModeDateAndTime,
   UIDatePickerModeCountDownTimer
} UIDatePickerMode;
Ab answered 21/7, 2011 at 9:38 Comment(0)
A
3

In Swift:

datePicker.datePickerMode = UIDatePickerMode.Time
Apolitical answered 28/7, 2015 at 21:55 Comment(0)
A
2
datePicker.datePickerMode = UIDatePickerModeTime;
Avertin answered 21/7, 2011 at 9:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.