Hide UIToolbar UIBarButtonItems

jmurphy picture jmurphy · Jun 4, 2010 · Viewed 20.4k times · Source

I have a UIToolbar that I set up using IB with three buttons, left, middle and right. In some situations I would like to not display the middle button. Does anybody know of a way to hide a specific button on inside a UIToolBar? There is no hide property, all I can find is setEnable but this still leaves the button causing users to wonder what its purpose is. I would like to only display it in situations that it actually has a use.

Thanks in advance!

Answer

Chris Cooper picture Chris Cooper · Jun 4, 2010

Reset the items:

-(void)setItems:(NSArray *)items animated:(BOOL)animated

You can get the current items using the items property, then just remove the one you don't want to show and pass in the new NSArray.

As you can see, you can also animate it to make it clear to the user.