Search code examples
iosswiftuitableviewuipickerview

iOS make UIPickerView in UITableViewCell fit in one row


I have a custom UITableView and I would like to display a picker in some of the rows. I have kind of achieved this by adding pickers to the accessoryView, for example

case 1:
    cell.textLabel?.text = "Color mode"
    let picker = UIPickerView()
    colorModeDelegate = ColorModeDelegate()
    picker.dataSource = colorModeDelegate
    picker.delegate = colorModeDelegate
    picker.showsSelectionIndicator = true
    cell.accessoryView = picker
    break

But the result is that the pickers expand above and below their cells, with the other alternative values and the result is a complete mess:

enter image description here

Is it possible to make these picker fit on one row, and display only the selected value (i.e kind of clip the visible area to the table cell). This is an example of what I would like to achieve. The last row shows in between two values as it in in the process of being changed (user is dragging)

enter image description here


Solution

  • I achieved something quite close by using setting the clipToBounds property of the table cell to true.