更改UIPickerView中文本的高度?

时间:2017-05-31 06:12:35

标签: ios swift uipickerview

如何更改UIPickerView中文本的高度?可能吗?我想降低默认高度。

1 个答案:

答案 0 :(得分:0)

SWIFT 2.2

在pickerView的委托中实现pickerView(pickerView:UIPickerView,viewForRow行:Int,forComponent组件:Int,reusingView view:UIView?)方法。

func pickerView(pickerView: UIPickerView, viewForRow row: Int, forComponent component: Int, reusingView view: UIView?) -> UIView {
let label: UILabel = UILabel(frame: CGRectMake(0, 0, scalePicker!.frame.size.width / 2, scalePicker!.frame.size.height / 7))
        label.textColor = UIColor.whiteColor()
        label.font = UIFont(name: "Gotham-Medium", size: 20)
        switch component {
        case 0:
            label.text = height_array[row] as? String
            label.textAlignment = .Center
        case 1:
            label.text = unit_Arr[row] as? String
            label.textAlignment = .Left
        default:
            break
        }

        return label
}