使用viewForRow自定义选取器视图的视图。似乎无法正确设置视图高度

时间:2018-02-28 05:10:52

标签: ios swift uipickerview

我尝试使用以下方法自定义pickerview行视图:

pickerView(_ pickerView: UIPickerView, viewForRow row: Int, forComponent component: Int, reusing view: UIView?) -> UIView

我遇到的问题是我从nib / xib加载的视图无法获得正确的行大小。

这是我的代码:

func pickerView(_ pickerView: UIPickerView, viewForRow row: Int, forComponent component: Int, reusing view: UIView?) -> UIView {
    if let reuseView = view as? ImageTypePickerView {
        return reuseView
    } else {
        let myRowView = ImageTypePickerReusableView()
        let indexPath = IndexPath(row: row, section: component)

        if let myUnitImageType = self.frc?.object(at: indexPath) as? UnitImageType {
            let image = UIImage(data: myUnitImageType.imageData! as Data)
            myRowView.typeImage.image = image
            myRowView.typeLabel.text = myUnitImageType.name
            myRowView.frame = CGRect(x: 0, y: 0, width:100, height: 108)

        }
        return myRowView
    }
}
我应该也用吗? :

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

    return 108
}

? ? ?

0 个答案:

没有答案