简体   繁体   English

iOS:UIPickerView默认尺寸

[英]iOS: UIPickerView default dimensions

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). 这将是默认设置(例如.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"). 我将UIPickerView放在一个弹出窗口中,并且UIPickerView的宽度大于320 px(这是.xib提供的“默认值”)。 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. 我想知道这些值,因此可以将它们添加到弹出框的宽度,以确保它不会切断UIPickerView右侧的组件。

Well this can be a little tricky since the Picker can have a dynamic number of components. 嗯,这可能有些棘手,因为Picker可以具有动态数量的组件。 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 . 这是从这里拉出来的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM