【问题标题】:How do I get the position of a component in UIPickerView?如何获取 UIPickerView 中组件的位置?
【发布时间】:2016-08-12 04:55:45
【问题描述】:

我想在 UIPickerView 中的组件旁边添加一个“min”标签。要确定 x 坐标,我需要知道组件的 x 坐标,以便根据不同的屏幕设备进行调整。

【问题讨论】:

  • 请提供更多细节以便更好地理解(如图片)。

标签: ios uipickerview


【解决方案1】:

您可以测试您的项目是否在func pickerView(pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? 中最后一个,并将最小文本添加到“组件”。

示例:

// MARK: - Properties

private var dataSource: [PickerViewItem] = [...]

// MARK: - UIPickerViewDataSource

func pickerView(pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
    if (row == self.dataSource.count - 1) {
        return "min: " + self.dataSource[row].description
    }
    return self.dataSource[row].description
}

如果你想要不同的字体或文本大小,你可以使用func pickerView(pickerView: UIPickerView, attributedTitleForRow row: Int, forComponent component: Int) -> NSAttributedString? 方法来格式化你的字符串。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-21
    • 2017-05-01
    相关资源
    最近更新 更多