Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIPickerView Width in iOS8 Swift

I simply can not find out how to get a width of a component on my UIPickerView. It's not allowing something simple (Int) as it needs to be CGFloat. What exactly do I put in the <#code#> section?

func pickerView(pickerView: UIPickerView, widthForComponent component: Int) -> CGFloat {
    <#code#>
}

Thank you!

like image 259
SID Avatar asked Dec 25 '22 20:12

SID


1 Answers

That method doesn't "get a width of a component..." The picker view calls that method to ask you how wide a component should be.

Your method could be as simple as:

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

(or whatever width is appropriate for your picker view...)

You just need to cast the result to the exptected type.

like image 138
Duncan C Avatar answered Feb 28 '23 05:02

Duncan C