Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save datayja/5534694 to your computer and use it in GitHub Desktop.
Save datayja/5534694 to your computer and use it in GitHub Desktop.
#import <UIKit/UIKit.h>
@interface UIBarButtonItem (GSTBackButtonFactory)
+ (UIBarButtonItem *)backButtonItemWithTitle:(NSString *)backButtonTitle;
@end
#import "UIBarButtonItem+GSTBackButtonFactory.h"
@implementation UIBarButtonItem (GSTBackButtonFactory)
+ (UIBarButtonItem *)backButtonItemWithTitle:(NSString *)aTitle
{
static NSMutableDictionary *buttonsCache;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
buttonsCache = [NSMutableDictionary dictionary];
});
UIBarButtonItem *backButtonItem = buttonsCache[aTitle];
if (backButtonItem == nil)
{
backButtonItem = buttonsCache[aTitle] =
[[UIBarButtonItem alloc] initWithTitle: aTitle
style: UIBarButtonItemStyleBordered
target: nil action: nil];
}
return backButtonItem;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment