1

I have a UIPickerView and it's gigantic by default and I'm not able to resize it.

below functions only resize the part that is selected but I want to make the entire picker view smaller. I don't need to see much of what's above and below the selected item. What would be the best way to do so folks? Thank you!!

func pickerView(_ pickerView: UIPickerView, viewForRow row: Int, forComponent component: Int, reusing view: UIView?) -> UIView {
    let view = UIView(frame: CGRect(x: 0, y: 0, width: 50, height:30))
    let label = UILabel(frame: CGRect(x: 0, y: 0, width: 50, height:30))
    label.text = speakerCount[row]
    view.addSubview(label)
    return view
}

func pickerView(_ pickerView: UIPickerView, rowHeightForComponent component: Int) -> CGFloat {
    return 30
}
  • A common approach is to have a control or list item display the current setting, and when it's tapped to change, present a modal with the UIPicker. For a simple example check out Apple's Clock app, Alarm view. When you click + (or, tap Edit and then tap an item), a modal with the UIPickerView appears to allow the user to change the value. – Corbell Jul 01 '20 at 22:40
  • Refer to [this](https://stackoverflow.com/questions/29816101/how-to-customise-uipickerview-height) post. This might help. – Preefix Jul 02 '20 at 11:55

0 Answers0