Swift Custom NavBar Back Button Image and Text

后端 未结 12 1314
谎友^
谎友^ 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:06

    Note: Please remember that the back button belongs to the the source ViewController and not to the destination ViewController. Thus, the modification needs to be done in the source VC, which is reflected to all the view in the navigation controller

    Code Snippet:

    let backImage = UIImage(named: "icon-back")
    
    self.navigationController?.navigationBar.backIndicatorImage = backImage
    
    self.navigationController?.navigationBar.backIndicatorTransitionMaskImage = backImage
    
    /*** If needed Assign Title Here ***/
    self.navigationItem.backBarButtonItem = UIBarButtonItem(title: "", style: UIBarButtonItemStyle.plain, target: nil, action: nil)
    

提交回复
热议问题