swift - 如何在 pickerview rowHeightForComponent 中获取行号?

标签 swift swift3

我有一个 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/

相关文章:

swift - IBDesignable 和 UITableViewCell

ios - 无需字段名称即可获取文档字段的所有值

swift - SCNReferenceNode 中没有可用的 SCNGeometry?

swift - Generic Decodable 无需解码

swift3 - Xcode 8 Beta 4 Swift 3 - "round"行为已更改

ios - 无法转换 LazyMapRandomAccessCollection 类型的值

ios - MPMusicPlayerControllerNowPlayingItemDidChange 在后台

arrays - Swift 数组字典、数据结构

ios - xcode 8 || AVPlayer正在显示视频,但未播放

ios - Firebase Child 必须是非空字符串且不包含