-1

I am writing an app , where I want custom back effect of the default OS. Like the system which is giving with Settings ( <) < Icon

Refer this image (I want the effect like Settings with the <)

enter image description here

I already have the functionality, I just want the look and feel.

Effect what I am getting. I have tried the following self.navigationItem.leftBarButtonItem = UIBarButtonItem(title: "Back", style: UIBarButtonItemStyle.Plain, target: self, action: "cancel") Also, I have tried adding it via Storyboard. How do I get it ?

onkar
  • 4,427
  • 10
  • 52
  • 89
  • Are you only asking how to add the visual effect for the button, and not the functionality for it? – Armin Jul 27 '16 at 09:55
  • Is this view being pushed onto a UINavigationController? Or is it being presented modally? – Fogmeister Jul 27 '16 at 10:10
  • Have you tried setting the backBarButtonItem instead of leftBarButtonItem? See: http://stackoverflow.com/questions/28471164/how-to-set-back-button-text-in-swift – Armin Jul 27 '16 at 10:13
  • In that case you really shouldn't be using a back button at all. Having a Done or Cancel button is what you should be doing. Back buttons with < are used specifically for when you are pushing hierarchical view controllers onto a navigation controller. When displaying things modally like this you should not use them. You shouldn't really be using the word "Back" at all here. – Fogmeister Jul 27 '16 at 10:18
  • @Armin the back button is only used when the view controller is pushed onto a navigation controller. This is not happening in this case. – Fogmeister Jul 27 '16 at 10:19
  • If it is being used in a "show" segue on a navigation controller then the back button will show the title of the previous screen alongside the <. So if you were to push a view on top of the login view controller here you would automatically get a "< Login" button. You can change the text by setting the `backBarButtonItem` on the Login screen to change what other screens show when you should go back to the Login screen. – Fogmeister Jul 27 '16 at 10:21
  • @onkar use a "show" segue like I said. – Fogmeister Jul 27 '16 at 10:33
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/118415/discussion-between-onkar-and-fogmeister). – onkar Jul 27 '16 at 10:35

1 Answers1

3

Use the backBarButtonItem and you will get right effect.

self.navigationItem.backBarButtonItem = UIBarButtonItem(title: "Back", style: UIBarButtonItemStyle.Plain, target: self, action: "cancel")

Also, you make sure

self.navigationItem.backBarButtonItem will be shown only after your have pushed another one view to navigation stack, controlled by self.navigationController, if no left button on navigation bar is displayed.

onkar
  • 4,427
  • 10
  • 52
  • 89