What is the best way to replace the Back button in UINavigationBar for iOS10 + with a custom picture? (no title required)

    1 answer 1

    Did this:

    class CustomViewController: UIViewController, UIGestureRecognizerDelegate { // MARK: - View Lifecycle override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view. addBackButton() } override func viewDidAppear(_ animated: Bool) { super.viewDidAppear(animated) navigationController?.interactivePopGestureRecognizer?.isEnabled = true } // MARK: - UI Events @objc func backButtonTapped() { _ = self.navigationController?.popViewController(animated: true) } // MARK: - Private Methods private func addBackButton() { let button = UIButton(type: .custom) button.setImage(UIImage(named: "iconNavBack"), for: .normal) button.addTarget(self, action: #selector(backButtonTapped), for: .touchUpInside) var buttonFrame = button.frame var buttonHeight: CGFloat = 44 if let navBarHeight = navigationController?.navigationBar.frame.size.height { buttonHeight = navBarHeight } buttonFrame.size = CGSize(width: 44, height: buttonHeight) // button.layer.borderWidth = 1 // button.layer.borderColor = UIColor.orange.cgColor button.frame = buttonFrame button.contentEdgeInsets = UIEdgeInsets(top: 0, left: -24, bottom: 0, right: 0) // NOTE: сдвигаСм Π»Π΅Π²Π΅Π΅ Π½Π΅ саму ΠΊΠ½ΠΎΠΏΠΊΡƒ, Π½ΠΎ ΠΈΠ·ΠΎΠ±Ρ€Π°ΠΆΠ΅Π½ΠΈΠ΅ Π½Π° Π½Π΅ΠΉ (Ссли Π½ΡƒΠΆΠ½ΠΎ ΠΏΠΎΠ΄Π²ΠΈΠ½ΡƒΡ‚ΡŒ ΠΏΠΎ Π΄ΠΈΠ·Π°ΠΉΠ½Ρƒ) navigationItem.leftBarButtonItem = UIBarButtonItem(customView: button) self.navigationController?.interactivePopGestureRecognizer?.delegate = self } }