我可以自定义UIDatePicker吗? [英] Can i customize UIDatePicker?

查看:113
本文介绍了我可以自定义UIDatePicker吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

如何自定义UIDatePicker

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

I need to customize UIDatePicker as we do support a variety of date formats like
dd-MM-yyyy, dd-MM-yyyy HH:mm:ss, dd-MM.

例如在日期和时间选择器模式下,选择器中的年份部分没有滚轮。因此提供的选择器模式是不够的。

E.g. in "date and time" picker mode, there is no roller for year part in picker.Hence the provided picker modes are not sufficient.

有没有办法自定义datepicker为所需的格式。

Is there any way to customize a datepicker for the desired formats.

推荐答案

绝对!
你不能用 UIDatePicker 这样做,因为它只支持4种日期格式,根据 UIDatePicker类参考;但是你可以使用 UIPickerView

Absolutely! You cannot do this with UIDatePicker as it only supports 4 date formats, according to the UIDatePicker Class Reference; however you can with a UIPickerView.

您需要实现 UIPickerViewDelegate 方法并为它们提供数据源,就像您使用a UITableView

You will need to need to implement UIPickerViewDelegate methods and provide them with a data source, just like you would with a 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吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆