UIPickerView Width in iOS8 Swift

不打扰是莪最后的温柔 提交于 2019-12-04 14:37:51

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.

The best way to return a width of a component is to use bounds.width:

func pickerView(pickerView: UIPickerView, widthForComponent component: Int) -> CGFloat 
{
  return self.view.bounds.width / x
}

Where x would be a number of the components you desire to have in a PickerView.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!