如何在UIDatePicker iphone中只显示时间

时间:2011-07-21 09:32:35

标签: iphone objective-c uiactionsheet

在我的应用中,我通过代码在操作表中显示UIDateTimePicker。它工作正常。 但我不想显示日期和日期。如何做到这一点。 请帮忙。提前谢谢。

代码:

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

4 个答案:

答案 0 :(得分:40)

datePicker.datePickerMode = UIDatePickerModeTime;

答案 1 :(得分:5)

datePickerMode属性设置为以下之一:

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

答案 2 :(得分:3)

在斯威夫特:

datePicker.datePickerMode = UIDatePickerMode.Time

答案 3 :(得分:2)

datePicker.datePickerMode = UIDatePickerModeTime;