UIPickerView无法正确显示图像

时间:2015-11-26 01:41:19

标签: ios swift uipickerview

我正在使用图片实现自定义选择器视图。问题是,图像彼此重叠,如下所示: enter image description here

这是在选择器视图中配置图像的代码:

func pickerView(pickerView: UIPickerView, viewForRow row: Int, forComponent component: Int, reusingView view: UIView!) -> UIView {
    let chosenImage: UIImageView = UIImageView(image: UIImage(named: iconArray[row]))
    NSLog("choosen image \(iconArray[row])")
    let workaroundImageView: UIImageView = UIImageView(frame: chosenImage.frame)
    workaroundImageView.backgroundColor = UIColor(patternImage: chosenImage.image!)
    return workaroundImageView
}

我错过了什么?有什么建议?

1 个答案:

答案 0 :(得分:1)

在UIPickerView的委托中使用rowHeightForComponent。

pickerView:rowHeightForComponent:

为组件提供所需的行高。

func pickerView(pickerView: UIPickerView!, rowHeightForComponent component: Int) -> CGFloat