Search code examples
iosswiftuipickerview

What can i do to resize the text and not show the ... in UIPickerView?


I am using 3 PickerViews and a few words are big and dont fit in PickerView and appear like this "IamAWordVer..." and i dont want this to happen. I want it resize the font or something like to fit all word in the PickerView but i dont to affect the size of the PickerView or the font size of the others picker views including the words in this PickerView where it happens.

For example all words use a default and if dont fit resize to fit all word.

func pickerView(pickerView: UIPickerView, viewForRow row: Int, forComponent component: Int, reusingView view: UIView?) -> UIView {
    let pickerLabel = UILabel()

    if pickerView == pvOne{
        pickerLabel.adjustsFontSizeToFitWidth = true
        pickerLabel.attributedText = oneText[row] as? NSAttributedString
    }
    else if(pickerView == pvTwo){
        pickerLabel.adjustsFontSizeToFitWidth = true
        pickerLabel.attributedText = twoText[row] as? NSAttributedString
    }
    else if(pickerView == pvThree){
        pickerLabel.adjustsFontSizeToFitWidth = true
        pickerLabel.attributedText = threeText[row] as? NSAttributedString
    }
    return pickerLabel
}

It show all empty now


Solution

  • Use nameOfLabel.adjustsFontSizeToFitWidth = true on it.