如何在UIPickerView中获取组件的位置?

时间:2016-08-12 04:55:45

标签: ios uipickerview

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

1 个答案:

答案 0 :(得分:1)

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

Egzample:

// 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?方法格式化字符串。