Ok, I solved the problem using a bit of a rough trick, but at least it works. If someone comes up with a more standard solution, please let me know!
Here is my code:
UIImage *backButtonImage = [[UIImage imageNamed:@"Graphics/Shared/navigation_back_button.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)]; [[UIBarButtonItem appearance] setBackButtonBackgroundImage:backButtonImage forState:UIControlStateNormal barMetrics:UIBarMetricsDefault]; [[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(0, backButtonImage.size.height*2) forBarMetrics:UIBarMetricsDefault];
This is in my appdelegate method:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
To stop stretching when used as a background, I used the idea of iOS 5: How to implement a custom (back) back button
But then changed it, instead of setting -
self.title = @" ";
Each time the view is loaded (and this may also go bad with the navigation bar title itself)
I just set the offset for the back button text to twice the height of the image, so you will never see it.
Why move on to all these troubles and not use the left button element with its own method to pull out the view controller?
The main reason is that you lose the standard sliding animation back to change views. In addition, this means that I do not need to use a custom button or write my own method to return. It just works.
Hope this solves the problem of another too, I know that I got stuck on it for 3 hours!
Dom chapman
source share