我可以自定义UIDatePicker吗?

时间:2012-12-18 13:52:01

标签: iphone ios ipad uidatepicker

  

可能重复:
  How to customize the UIDatePicker

我需要自定义UIDatePicker,因为我们支持各种日期格式,如dd-MM-yyyydd-MM-yyyy HH:mm:ssdd-MM

E.g。在“日期和时间”选择器模式下,拾取器中的年份部分没有滚轮。因此提供的拾取器模式是不够的。

有没有办法为所需格式自定义日期选择器。

2 个答案:

答案 0 :(得分:1)

UIDatePicker支持the documentation中详述的四个datePickerMode常量。您无法提供自定义日期格式。但是,根据您的应用程序和要求,您可以使用标准的选择器视图:我已经完成了这个,我只需要显示几个月的列表。

答案 1 :(得分:1)

绝对! 根据{{​​3}},您无法使用UIDatePicker执行此操作,因为它仅支持4种日期格式;但是你可以使用UIPickerView

您需要实施UIPickerViewDelegate方法并为其提供数据源,就像使用UITableView一样:

- (NSInteger)numberOfComponentsInPickerView: (UIPickerView*)thePickerView {
   return /* # of columns you need */;
}

- (NSInteger)pickerView:(UIPickerView *)thePickerView numberOfRowsInComponent:(NSInteger)component
{
   return /* # of rows per component */;
}

- (NSString *)pickerView:(UIPickerView *)thePickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
   return /* date source/string/title for the row */;
}

参考:UIDatePicker Class Reference

相关问题