2

I am trying to make a custom back button but also want to retain the default look of the back button. I simply want the look of the default back arrow (<) without any text. The code I am using is

    let newBackButton = UIBarButtonItem(title: "<", style: UIBarButtonItemStyle.Plain, target: self, action: "goBack")
    navigationItem.leftBarButtonItem = newBackButton

But this makes the back button looks all wrong. I can't find anywhere how/what to change the button to look like the default look. Thanks for any help.

Tamarisk
  • 929
  • 2
  • 11
  • 27
  • You can check the answers : http://stackoverflow.com/questions/31717315/perform-segue-on-press-on-back-button/31717425#31717425 | http://stackoverflow.com/questions/31807997/back-button-image-what-is-it-called-in-swift/31808361#31808361 – Ashish Kakkad Sep 11 '15 at 03:57
  • no need of coding , r u used the storyboard or xib – Anbu.Karthik Sep 11 '15 at 05:08

1 Answers1

2

If you have more than one View controller on the Stack default back arrow will come automatically by using simple below code:-

self.navigationController?.backBarButtonItem = UIBarButtonItem(//your code);

If you do not have more than one View controller on the Stack then you can do the tweak by putting the back button image like this:-

let newBackButton = UIBarButtonItem(image: "BackButtonimage", style: UIBarButtonItemStyle.plain, target: self, action: "goBack")
navigationItem.leftBarButtonItem = newBackButton
Hussain Shabbir
  • 14,801
  • 5
  • 40
  • 56
  • The problem with this is that the "goBack" function (see original post) is never called by the system. – Henning Mar 06 '17 at 14:48