Can i customize UIDatePicker? [duplicate]

…衆ロ難τιáo~ 提交于 2019-12-12 03:33:06

问题


Possible Duplicate:
How to customize the UIDatePicker

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.

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


回答1:


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.

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 */;
}

Reference: here




回答2:


A UIDatePicker supports the four datePickerMode constants detailed in the documentation. You can't provide custom date formats. However, depending on your application and requirements you could just use a standard picker view: I've done this where I only need to display a list of months.



来源:https://stackoverflow.com/questions/13934477/can-i-customize-uidatepicker

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