0
0

More than 1 year has passed since last update.

NavigationBarのカスタムBackボタンの見た目をデフォルトと合わせる

Last updated at Posted at 2023-01-25

デフォルトのBackボタン(アイコンのみ)と見た目をほぼほぼ合わせることができたのでメモ。

Backボタンタップ時にアラート表示したいときなどにBackボタンの見た目をほぼ変えずに対応できるようになります!

Default Custom
Simulator Screen Shot - iPhone 8 - 2023-01-25 at 19.38.40.png Simulator Screen Shot - iPhone 8 - 2023-01-30 at 14.33.36.png
let imageConfig = UIImage.SymbolConfiguration(pointSize: 22, weight: .medium, scale: .default)
let image = UIImage(systemName: "chevron.left", withConfiguration: imageConfig)
let buttonItem = UIBarButtonItem(image: image, style: .plain, target: target, action: action)
buttonItem.imageInsets = UIEdgeInsets(top: 0, left: -8, bottom: 0, right: 0)
navigationItem.leftBarButtonItem = buttonItem

ポイントはUIImage.SymbolConfigurationをセットするのとimageInsetsで左の余分なマージンを消すこと。
Customのアイコンの位置が微妙に上になってしまったがimageInsetsのtop/bottomがなぜか効かなかった:thinking:

0
0
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
0