Iphone UIPickerView帧大小-边距问题

Iphone UIPickerView帧大小-边距问题,iphone,border,uipickerview,margin,frame,Iphone,Border,Uipickerview,Margin,Frame,我似乎在任何地方都找不到这个问题的答案——希望有人能帮忙!有人知道如何确定iOS给挑选者带来的利润吗 我已经编写了一个通用视图,它显示一个UIPickerView,在适当的位置上有许多数字和标签。UIPickerView是在interface builder中创建的,并填充整个屏幕。我目前正在使用UIPickerView的“frame”属性来确定选择器的宽度,并计算单个组件的宽度和标签位置 更新 根据要求-我已尝试包含代码。我正在构建的是一个通用的UIViewController,它在相关的.x

我似乎在任何地方都找不到这个问题的答案——希望有人能帮忙!有人知道如何确定iOS给挑选者带来的利润吗

我已经编写了一个通用视图,它显示一个UIPickerView,在适当的位置上有许多数字和标签。UIPickerView是在interface builder中创建的,并填充整个屏幕。我目前正在使用UIPickerView的“frame”属性来确定选择器的宽度,并计算单个组件的宽度和标签位置

更新 根据要求-我已尝试包含代码。我正在构建的是一个通用的UIViewController,它在相关的.xib文件中有一个选择器-每当我需要输入任何数值时,只要给它必要的参数,我就会将其作为模式视图加载。在Interface Builder中,选择器被设置为“居中”模式——我也尝试过其他一些模式,但似乎没有什么对布局产生任何影响

该类接受位数、小数位数以及单元描述。然后由这些值确定组件的数量,并在选择器组件上适当放置两个标签,以显示小数点和单位标签。viewDidLoad方法如下所示。它生成一个在UIPickerView委托方法中使用的标准组件宽度。数学似乎都很好,但定位出现了问题,我认为这是由于采摘器边缘周围的余量造成的

unitLabel.text = [NSString stringWithFormat:@"%@", unitDescription];
CGSize labelSize = [[unitLabel text] sizeWithFont:[unitLabel font]];
labelWidth = labelSize.width;

decimalPoint.text = [NSString stringWithFormat:@"."];
CGSize pointSize = [[decimalPoint text] sizeWithFont:[decimalPoint font]];
dpWidth = pointSize.width;
if (decimalPlaces == 0) {
    // Hide the decimal point
    decimalPoint.hidden = YES;
    dpWidth = 0;
}
else {
    decimalPoint.hidden = NO;
}

CGFloat pickerWidth = picker.frame.size.width;
//Now determine the standard component width
componentWidth = (pickerWidth - labelWidth - dpWidth) / (digits + decimalPlaces);   

//Now position the decimal point and label
//The components will be centred on the screen, so the location for the labels will be:
//Decimal point:
//Left position of picker + (componentWidth * digits)
//Unit:
//Left position of picker + (componentWidth * digits) + dpWidth + (componentWidth * decimalPlaces)
//Where:
//Left position of picker = screen width  -  (componentWidth * digits) + dpWidth + (componentWidth * decimalPlaces) + labelWidth
//                          ------------     -----------------------------------------------------------------------------------
//                                2                                 2
//
CGFloat leftPos = (picker.frame.size.width / 2) - (((componentWidth * digits) + dpWidth + (componentWidth * decimalPlaces) + labelWidth) / 2);
CGFloat dpPos = leftPos + (componentWidth * digits);
CGFloat labelPos = leftPos + (componentWidth * digits) + dpWidth + (componentWidth * decimalPlaces);

CGRect dpFrame = decimalPoint.frame;
dpFrame.origin.x = dpPos;
dpFrame.origin.y = picker.center.y - (5 * (pointSize.height / 12));
decimalPoint.frame = dpFrame;

CGRect labelFrame = unitLabel.frame;
labelFrame.origin.x = labelPos;
labelFrame.origin.y = picker.center.y - (5 * (labelSize.height / 12));
unitLabel.frame = labelFrame;

也许发布一些你正在使用的代码。另外,您的选择器中有多少组件?已按要求使用代码进行更新-抱歉,有点长!组件的数量由要输入的值的位数和小数位数决定,因此在运行时会有所不同。