0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

UIPickerView 文字のサイズを合わせる

Posted at

UIPickerViewの選択肢が長くて入らない場合

UIPickerView上のラベルの文字サイズを調整してピッカー内に入るようにする。

func pickerView(_ pickerView: UIPickerView, viewForRow row: Int, 
        forComponent component: Int, reusing view: UIView?) -> UIView 
{
    let label = (view as? UILabel) ?? UILabel()
    label.text = self.addresses[row]
    label.textAlignment = .center
    label.adjustsFontSizeToFitWidth = true
    return label
}

view が取れない場合もあるので ?? UILabel() を忘れないように

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?