2022年11月26日土曜日

UITabBarItemにMaterial Designのアイコンを余白を調整して表示する方法

 環境

  • MacBook Pro (Retina, 13-inch, Early 2015)
  • XCode Version 13.4.1 (13F100)
  • Swift 5
  • Storyboard

やりたいこと

UITabBarItemにMaterial Designのアイコンを表示する

はまったポイント

Material Designのアイコンを表示するときに余白が設定されない




実装方法

Material Designのアイコンはこちら
SVG形式のものをダウンロードしてAssetsへImage Setを追加して登録。





ターゲット側のBarItemを選択して

Attribute InspectorでImage(とLandscape)を設定。



Size InspectorのImage Insetを指定する。Landscapeの場合はLandscape Image Insetも設定。





出来上がり


わかってしまえば簡単だが意外と情報に行き着けずにはまったのでメモ。