James Lim
James Lim

Reputation: 83

UIPickerView automatic dimensions

For dynamic row heights in UITableView Swift has

UITableViewAutomaticDimension

Is there an equivalent for UIPickerView

Upvotes: 0

Views: 124

Answers (1)

Matan
Matan

Reputation: 1003

You may try to get the number of characters of your pickerView Row String and duplicate it by some number of pixels in order to get a decent row width that will fit dynamically to your content. I had to do that when displaying live prices and made something like that:

func pickerView(_ pickerView: UIPickerView, widthForComponent component: Int) -> CGFloat {
    let charcterWidth = 20
    let priceComponentWidth = CGFloat((self.lastPrice?.formatStringWithCommasOnly().count ?? 0) * charcterWidth)
    return priceComponentWidth
}

Upvotes: -1

Related Questions