1

Ok so currently in the app I'm working on, I'm using (read: hacking) a UIDatePicker with the mode set to UIDatePickerModeCountDownTimer to allow users to enter the amount of time they waited. The issue with this is that you can't limit the maximum value (I want it to be 5 hours), as UIDatePickerModeCountDownTimer ignores the maximumDate and minimumDate properties.

So I tried changing the mode to UIDatePickerModeTime, which does allow me to set limits. The problem now, is that UIDatePickerModeTime doesn't seem to call widthForComponent: or titleForRow: and the components are really thin and don't have titles.

Previously, they looked really nice, but the limits were not adjustable. How can I change the width of these components? I added screenshots so you can see what I mean (pardon the french in the pics, I was working in the French localization of the app).

This is my first post on SO, after using it ALL the time so if I forgot anything, let me know. I would post the code, but I don't think I'm allowed to (company rules), and it's all convoluted anyways.

This is with the mode set to UIDatePickerModeCountDownTimer (aka how I want it to look):

https://i.stack.imgur.com/TVukq.png

And this is how it looks with the mode set to UIDatePickerModeTime (aka the one that has more functionality, but doesn't look as good):

https://i.stack.imgur.com/AG581.png

Alternatively, if anyone has a way for me to place an upper limit on the UIDatePickerModeCountDownTimer one and also enable "0 hours 0 minutes" in that mode (currently, it disables this option since its designed to be a count down timer), please let me know!

Thanks!

PS: I'm using iOS SDK 6.0 and ARC with a deployment target of iOS 5.0+

PPS: "Spam Prevention" wouldn't let me post images since I have no rep. So i left the imgur links

EDIT: here's the code i have in setting the width of the components. I have other custom UIPickers in my app with data sources and all that stuff, but I'd rather not make another custom UIPicker just for something that should be so simple.

- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {

    if(component == 0){
        return [NSString stringWithFormat:@"Hours"];
    }else if (component == 1){
        return [NSString stringWithFormat:@"Minutes"];
    }

}


- (CGFloat)pickerView:(UIPickerView *)pickerView widthForComponent:(NSInteger)component {

    return 160.0f;

}
Matthew Davis
  • 173
  • 10
  • You cannot customize UIDatePicker in anyway. If you want a customized look then use UIPickerView. Otherwise accept UIDatePicker as it looks like.. :-{ – Dinesh Raja Dec 10 '12 at 16:03
  • I don't have the solution to increase the width of your UIDatePicker. But you can limit the maximum hours in UIDatePickerModeCountDownTimer by the following questions and answers. Try these. http://stackoverflow.com/a/2439271/1083859 http://stackoverflow.com/q/8547514/1083859 – Dinesh Raja Dec 10 '12 at 16:08
  • @R.A I saw both of those. Unfortunately, neither are what I need. The `countDownDuration` property only lets me pick the initial selected time, not limit the selectable time. If I could enable/disable certain values, the same way the 0 minutes is enabled only if the hour is greater than 0, then my problem would be solved. – Matthew Davis Dec 10 '12 at 16:33

0 Answers0