Reputation: 83
For dynamic row heights in UITableView
Swift has
UITableViewAutomaticDimension
Is there an equivalent for UIPickerView
Upvotes: 0
Views: 124
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