1

I would like to know the width of the dark grey frame on either side of the inside picker part and the width of the separators between components. This would be at default settings (eg. what's shown in the .xib). Or, how to find such values programmatically. Thank you

To clarify, I'm looking for what the "suggested minimums" might be for those values. I'm putting my UIPickerView in a popover, and the UIPickerView is wider than 320 px (which is what the .xib gives as the "default"). I would like to know these values so I can add them to the popover's width to make sure it doesn't cut off components on the right side of the UIPickerView.

alsuhr
  • 129
  • 2
  • 11

1 Answers1

1

Well this can be a little tricky since the Picker can have a dynamic number of components. So in order to find the widths you have to take into account the number of components. This can be done like so:

        NSInteger n = picker.numberOfComponents;        

        const CGFloat separatorWidth = 8.0f;
        const CGFloat sectionExceedWidth = -2.0f;
        CGFloat totalWidth = picker.bounds.size.width;
        CGFloat panesWidth = totalWidth - separatorWidth * (n - 1);
        for (NSInteger i = 0; i < n; i++) {
            CGFloat sectionWidth = [picker rowSizeForComponent:i].width + sectionExceedWidth;
            panesWidth -= sectionWidth;
        }
        CGFloat leftPaneWidth = ceilf(panesWidth * 0.5f);
        CGFloat rightPaneWidth = panesWidth - leftPaneWidth;
        CGFloat totalHeight = picker.bounds.size.height;
        CGRect totalRect = CGRectMake(0, 0, totalWidth, totalHeight);

Where the left and right panes widths are found and the separator size is static.

This was pulled from here.

random
  • 8,568
  • 12
  • 50
  • 85
  • Ok, that is helpful! But I guess to rephrase my question a little better, I am looking for the "suggested minimum" of those values. I'm putting my UIPickerView in a popover. My UIPickerView has many components, so it's wider than the default width (which is in the .xib; 320 px). I want to know what the suggested minimum for the parts of the dark grey area on the sides is so that I can add that to popover width when creating the popover, so it doesn't squeeze the picker and cut off components on the right. Is there a way to find that programmatically? – alsuhr Jul 17 '12 at 13:30
  • I don't believe that Apple has put out any minimum values officially. I believe that it is more a matter of how small can it get while still being 1. functional 2. not ugly. I would just play around with different sizes until you reach the smallest possible. Then just hard code it as a minimum threshold. – random Jul 23 '12 at 20:04