I'm trying to get a back button without a title but I can't make it work. I am really new in objective-c...
UIImage *backButtonImage = [[UIImage imageNamed:@"back.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 30, 50)];
[[UIBarButtonItem appearance] setBackButtonBackgroundImage:backButtonImage
                                                  forState:UIControlStateNormal
                                                barMetrics:UIBarMetricsDefault];
With that code I have my back button but also the title of the previous page.
I found some working examples using the class UIViewController but in my case the code is in the appDelegate.m file.
Any idea how I can make it work ?
A very easy hack that I adapted which uses the iOS 5 appearance proxy is the following (needless to say, the benefit of the proxy is global change to all nav bars):
[[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(-400.f, 0)
                                                     forBarMetrics:UIBarMetricsDefault];
This method is available in iOS 5 SDK, so no worries there.
EDIT
In order to avoid the image stretching, use the following:
UIImage* image = [UIImage imageNamed:@"back"];
return [image resizableImageWithCapInsets:UIEdgeInsetsMake(0, image.size.width, 0, 0)];
                        From what I can tell, you're setting the appearance proxy correctly. The issue here is setting a new title for your back button.
To do so, create a custom button with your behaviour, and use that as your new back button. Set this before you push or pop said view controller, such as in init
UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:@""
                                                               style:UIBarButtonItemStyleBordered
                                                              target:nil
                                                              action:nil];
[self.navigationItem setBackBarButtonItem: newBackButton];
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With