문제

How can i display the UIDatePicker with format HH:MM:SS as there is no mode for this in UIDatePicker.Currently it is showing the date and time.I get to know that ,I have to use NSDate format .But I don't know how to use it.

I need to do this As I am getting the value in a format HH:MM:SS. need to display it on the picker and then change to any value after that have to save it .

below is the code that I use to create the custom picker.

CGRect pickerFrame = CGRectMake(0,self.view.bounds.size.height-250,0,0);
UIDatePicker *myPicker = [[UIDatePicker alloc] initWithFrame:pickerFrame];
myPicker.backgroundColor = [UIColor lightTextColor];
myPicker.layer.cornerRadius = 10;
myPicker.layer.masksToBounds=YES;

How and where can I use the formatter so that it display the following format .

NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"HH:mm:ss"];
도움이 되었습니까?

해결책

There are following types of modes available in UIDatePicker:

UIDatePickerModeTime,
UIDatePickerModeDate,
UIDatePickerModeDateAndTime,
UIDatePickerModeCountDownTimer

With the following you can show time:

datePicker.datePickerMode = UIDatePickerModeTime;

But both date and time can not be shown.

What you can do is either subclass UIPickerView or in after selecting the Date, prompt user to select time using the above pickerMode.

다른 팁

You can only use UIDatePicker to display the set of standard formats.

If you want to display anything else you will have to use a custom UIPickerView.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top