Change width of components in UIDatePickerModeTime

671 Views Asked by At

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;

}
0

There are 0 best solutions below