Swift Custom NavBar Back Button Image and Text

后端 未结 12 1293
谎友^
谎友^ 2021-01-30 10:40

I need to customise the look of a back button in a Swift project.

Here\'s what I have:

Here\'s what I want:

I\'ve tried creating my own UIBarButtonItem

12条回答
  •  执笔经年
    2021-01-30 11:02

    Just replace the backButton with a custom rightBarButtonItem

    let backImage = UIImage(named: "BackBtn")?.withRenderingMode(.alwaysOriginal)
        navigationItem.leftBarButtonItem = UIBarButtonItem(image: backImage, style: .plain, target: self, action: #selector(popnav))
    
        @objc func popnav() {
        self.navigationController?.popViewController(animated: true)
    }
    

提交回复
热议问题