Custom back button in UINavigationController

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 🙂 .

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.