how to display only time in UIDatePicker iphone

三世轮回 提交于 2019-12-23 06:48:27

问题


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

回答1:


datePicker.datePickerMode = UIDatePickerModeTime;



回答2:


Set the datePickerMode property to one of the following:

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



回答3:


In Swift:

datePicker.datePickerMode = UIDatePickerMode.Time



回答4:


datePicker.datePickerMode = UIDatePickerModeTime;


来源:https://stackoverflow.com/questions/6774020/how-to-display-only-time-in-uidatepicker-iphone

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!