开发者

How can I change the width of each component in a UIPickerView?

开发者 https://www.devze.com 2023-01-28 06:01 出处:网络
How can I change the width of each component in a UIP开发者_JAVA百科ickerView?Implement pickerView:widthForComponent: method in picker\'s delegate and return appropriate width for each component from

How can I change the width of each component in a UIP开发者_JAVA百科ickerView?


Implement pickerView:widthForComponent: method in picker's delegate and return appropriate width for each component from it. e.g.

- (CGFloat)pickerView:(UIPickerView *)pickerView widthForComponent:(NSInteger)component{
      switch (component){
           case 0: 
                return 100.0f;
           case 1: 
                return 60.0f;
     }
      return 0;
}


Swift 4 version:

func pickerView(_ pickerView: UIPickerView, widthForComponent component: Int) -> CGFloat {
    let w = pickerView.frame.size.width
    return component == 0 ? (2 / 3.0) * w : (1 / 3.0) * w
}

in this example: 2/3 of width for first component and 1/3 for the second

Using fixed values may be a bad idea, because of various screen sizes.

0

精彩评论

暂无评论...
验证码 换一张
取 消