Subclass UIBarButtonItem
.
Make sure the button in Interface Builder is set to HidableBarButtonItem
.
Make an outlet from the button to the view controller. From the view controller you can then hide/show the button by calling setHidden:
HidableBarButtonItem.h
#import <UIKit/UIKit.h>
@interface HidableBarButtonItem : UIBarButtonItem
@property (nonatomic) BOOL hidden;
@end
HidableBarButtonItem.m
#import "HidableBarButtonItem.h"
@implementation HidableBarButtonItem
- (void)setHidden:(BOOL const)hidden {
_hidden = hidden;
self.enabled = hidden ? YES : NO;
self.tintColor = hidden ? [UIApplication sharedApplication].keyWindow.tintColor : [UIColor clearColor];
}
@end