iOS:UIPickerView默认尺寸

时间:2012-07-16 17:33:14

标签: objective-c ios uipickerview

我想知道内部拾取器部件两侧的深灰色框架宽度和组件之间隔板的宽度。这将是默认设置(例如.xib中显示的内容)。或者,如何以编程方式查找此类值。谢谢

为了澄清,我正在寻找这些值的“建议最小值”。我把UIPickerView放在一个popover中,而UIPickerView的宽度超过320 px(这就是.xib给出的“默认”)。我想知道这些值,所以我可以将它们添加到popover的宽度,以确保它不会切断UIPickerView右侧的组件。

1 个答案:

答案 0 :(得分:1)

这可能有点棘手,因为Picker可以拥有动态数量的组件。因此,为了找到宽度,您必须考虑组件的数量。这可以这样做:

        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);

找到左窗格和右窗格宽度且分隔符大小为静态。

这是从here中提取的。

相关问题