LoginSignup
2

More than 1 year has passed since last update.

【Swift5】NavigationBarのBackボタンを画像にする

Posted at

NavigationBarの< Backボタンを画像にする

これを
スクリーンショット 2022-08-03 23.08.55.png
これにする
スクリーンショット 2022-08-03 23.12.38.png

コード

ViewController.swift
    private func setNaviBackButton() {
        let backImage = UIImage(named: "backIcon")?.withRenderingMode(.alwaysOriginal)
        navigationItem.leftBarButtonItem = UIBarButtonItem.init(image: backImage, style: .plain, target: self, action: #selector(tappedBackButton))
    }

    @objc func tappedBackButton() {
        self.navigationController?.popViewController(animated: true)
    }

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
2