iOS8 Swift中的UIPickerView宽度 [英] UIPickerView Width in iOS8 Swift
本文介绍了iOS8 Swift中的UIPickerView宽度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我根本无法找到如何在UIPickerView上获取组件的宽度。它不允许简单的(Int),因为它需要是CGFloat。我在< #code#>部分放置了什么?
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#>
}
谢谢!
推荐答案
该方法不获取组件的宽度......选择器视图调用该方法来询问组件应该有多宽。
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.
你的方法可以很简单:
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.
这篇关于iOS8 Swift中的UIPickerView宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文