LoginSignup
0
1

【Swift】UITabBarに表示したシンボルイメージの位置をずらす方法

Posted at

通常の場合、UITabBarItemの画像の表示位置をずらす方法として、imageInsetsを変更する方法があります。

tabBarItem.imageInsets = UIEdgeInsets(top: 10, left: 0, bottom: -10, right: 0)

しかし、SF Symbolsのシンボルイメージだとこの方法で位置をずらせなかったため、調べた方法を共有したいと思います。

.withBaselineOffset(fromBottom: CGFloat)

let houseImage = UIImage(systemName: "house.fill")?.withBaselineOffset(fromBottom: 10)
let tabBarItem = UITabBarItem(title: nil, image: houseImage, tag: 0)

シンボルイメージに.withBaselineOffset(fromBottom: 10)を設定することで、画像を下に10ずらすことができます。
今回は画像のみ表示したいのでtitlenilにしています。

また、.withConfiguration(UIImage.SymbolConfiguration(weight: .bold))などでシンボルイメージのサイズやweightを変えることもできます。

参考

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