Tag Archives: UIBarButton

How to hide a UIBarButtonItem in your Navigation Controller

Since UIBarButtonItems do not have a “hidden” property, we can’t just set this to yes and it’ll disappear. Instead, we can set them to nil.

In this example we’re hiding the right item in the navigation controller:

How to create a UIBarButtonItem in code and make it call a method

Some things are really easy to do via a Storyboard – but when you want to create the same thing in code I frequently forget how to do it.

Turns out it’s equally simple: this example assumes you have a View Controller which is embedded in a Navigation Controller (so it already has a UINavigationBar at the top). Here’s how you add a button to it, set the title and target, and tell it what to do when it’s pressed:

You can set the button on the left hand site by using self.navigationItem.leftBarButtonItem