Skip to content

Instantly share code, notes, and snippets.

@MoathOthman
Created March 22, 2015 17:08
Show Gist options
  • Save MoathOthman/c6b0729f45edbac1a46f to your computer and use it in GitHub Desktop.
Save MoathOthman/c6b0729f45edbac1a46f to your computer and use it in GitHub Desktop.
Custom UINavigationController back button
Snippet From Apple sample Code
UIImage *backButtonBackgroundImage = [UIImage imageNamed:@"back"];
// The background should be pinned to the left and not stretch.
float margin = 12.0;
backButtonBackgroundImage = [backButtonBackgroundImage resizableImageWithCapInsets:UIEdgeInsetsMake(0, backButtonBackgroundImage.size.width - margin, 0, 0)];
id appearance = [UIBarButtonItem appearanceWhenContainedIn:[
CustomBackButtonNavController class], nil];
[appearance setBackButtonBackgroundImage:backButtonBackgroundImage forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
UIBarButtonItem *backBarButton = [[UIBarButtonItem alloc] initWithTitle:@" " style:UIBarButtonItemStylePlain target:nil action:nil];
self.navigationItem.backBarButtonItem = backBarButton;
Just one note : the image you use may have different size an though needs different margin Value ;
Just another: CustomBackButtonNavController can be replaced with UINavigationController in case you are using the same back button all over the app as in my most cases :) .
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment