ishhhh
ishhhh

Reputation: 647

how to display only time in UIDatePicker iphone

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];

Upvotes: 24

Views: 18512

Answers (4)

Ever Uribe
Ever Uribe

Reputation: 669

In Swift:

datePicker.datePickerMode = UIDatePickerMode.Time

Upvotes: 3

Praveen S
Praveen S

Reputation: 10393

Set the datePickerMode property to one of the following:

typedef enum {
   UIDatePickerModeTime,
   UIDatePickerModeDate,
   UIDatePickerModeDateAndTime,
   UIDatePickerModeCountDownTimer
} UIDatePickerMode;

Upvotes: 7

Alex Coplan
Alex Coplan

Reputation: 13371

datePicker.datePickerMode = UIDatePickerModeTime;

Upvotes: 2

Vaishnavi Naidu
Vaishnavi Naidu

Reputation: 2617

datePicker.datePickerMode = UIDatePickerModeTime;

Upvotes: 41

Related Questions