我有一个 pickerview,它可能有不同的行高,这取决于传递的数组中的文本:
func pickerView(_ pickerView: UIPickerView, viewForRow row: Int, forComponent component: Int, reusing view: UIView?) -> UIView {
let label = UILabel(frame: CGRect(x: 0, y: 0, width: screenWidth, height: 44));
label.lineBreakMode = .byWordWrapping;
label.numberOfLines = 0;
label.text = array[row]
label.sizeToFit()
return label;
}
func pickerView(_ pickerView: UIPickerView, rowHeightForComponent component: Int) -> CGFloat {
// How to get the the row number of pickerview here?
return 0
}
最佳答案
I have a pickerview that may have different height of the row depends on the text on passed array
不,您没有这样的选择器 View 。选择器 View 不能有可变的行高。你找不到方法的原因是没有这样的方法。
关于swift - 如何在 pickerview rowHeightForComponent 中获取行号?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56248650/