Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
iOS custom back button category.
//
// UIViewController+JIMBackButton.h
// CupMaster
//
// Created by Juan Felipe Alvarez Saldarriaga on 11/7/13.
// Copyright (c) 2013 juan.im. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface UIViewController (JIMBackButton)
- (void)JIM_setupCustomBackButton;
@end
//
// UIViewController+JIMBackButton.m
// CupMaster
//
// Created by Juan Felipe Alvarez Saldarriaga on 11/7/13.
// Copyright (c) 2013 juan.im. All rights reserved.
//
#import "UIViewController+JIMBackButton.h"
@implementation UIViewController (JIMBackButton)
- (void)JIM_setupCustomBackButton
{
self.navigationItem.hidesBackButton = YES;
if ([self.navigationController.viewControllers count] <= 0) {
return;
}
if ([self.navigationController.visibleViewController isEqual:self.navigationController.viewControllers[0]]) {
return;
}
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"⬅︎" style:UIBarButtonItemStylePlain target:self action:@selector(JIM_customBackButtonPressed:)];
}
- (IBAction)JIM_customBackButtonPressed:(id)sender
{
[self.navigationController popViewControllerAnimated:YES];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.