I have a bar button item set to a custom image from my image assets folder. After launch, once the user presses the button, I want it to change to a system item—the stop (X) button. I know how to programmatically change the image of the bar button, but how do I change the image to one of the system items in my code?
Swift 3, Xcode 8 beta 1.
Edit Here are the system items I'm referencing:

How can I change my button's image to one of those system items from my code?
What you need to do is to have two buttons (you can set them programmatically or in interface builder), one with the image and another one with the stop behavior. When one is pressed, toggle the visibility of both.
I believe the best option is to do it programmatically, so this is how:
Add two bar button items as class members:
Then in the
viewDidLoadset the values as you want (one to have an image, the other to have the normal behavior with the "X"). Then add theitemOnbutton to the navigation bar:Be aware that both should have the same action:
Then implement the toggleVisibleButton function:
Update for Swift 3:
Set the action like this: