Swift Custom NavBar Back Button Image and Text

后端 未结 12 1295
谎友^
谎友^ 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 10:54

    This worked for me on iOS 13 using swift 5. Just hide the original back button and add a new navigation left bar button item with an action.

    navigationItem.hidesBackButton = true
    navigationItem.leftBarButtonItem = UIBarButtonItem(image: #imageLiteral(resourceName: "backBtn"), style: .plain, target: self, action: #selector(back(sender:)))
    
    @objc func back(sender: UIBarButtonItem) {
        self.navigationController?.popViewController(animated:true)
    }
    

提交回复
热议问题