Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios UIPickerView';s零部件宽度在自定义时会导致对齐问题_Ios_Objective C_Swift_Uipickerview - Fatal编程技术网

Ios UIPickerView';s零部件宽度在自定义时会导致对齐问题

Ios UIPickerView';s零部件宽度在自定义时会导致对齐问题,ios,objective-c,swift,uipickerview,Ios,Objective C,Swift,Uipickerview,我的UIPickerView与其superview具有相同的宽度。我希望能够更改组件/列的宽度: func pickerView(pickerView: UIPickerView, widthForComponent component: Int) -> CGFloat { if component == 0 { return pickerViewHolder.bounds.width / 100 * 10 } else if component ==

我的UIPickerView与其superview具有相同的宽度。我希望能够更改组件/列的宽度:

func pickerView(pickerView: UIPickerView, widthForComponent component: Int) -> CGFloat {

    if component == 0 {

        return pickerViewHolder.bounds.width / 100 * 10

    } else if component == 1 {

        return pickerViewHolder.bounds.width / 100 * 45

    } else {

        return pickerViewHolder.bounds.width / 100 * 45
    }

}
使用该代码,宽度显示为所需的宽度。但组件行内的对齐方式存在差异。在
viewForRow
中,我设置了
NSTextAlignment.Left
什么实际适用于标准组件宽度或-在那里我用一个大问号-只使用一些自定义值,如(15、30、30)或(30、30、30)。但是,如果我将上面的数字或其他总数小于100%(如果这很重要)的组合(如(10、40、40)或(10、45、40)放入,我仍然可以在所选行中获得正确的对齐方式,但上面和下面的对齐方式不同:

我尝试调用
pickerView.setNeedsLayout()或
pickerView.reloadAllComponents()
视图中的
pickerView.setNeedsLayout()或
reloadAllComponents()