SetBackButtonBackgroundImage without IOS5 header

I am trying to get the back button without a title, but I cannot get it to work. I am really new to objective-c ...

UIImage *backButtonImage = [[UIImage imageNamed:@"back.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 30, 50)]; [[UIBarButtonItem appearance] setBackButtonBackgroundImage:backButtonImage forState:UIControlStateNormal barMetrics:UIBarMetricsDefault]; 

With this code, I have my back button, but also the name of the previous page.

I found some working examples using the UIViewController class, but in my case the code is in the appDelegate.m file.

Any idea how I can make it work?

+8
user-interface objective-c xcode ios5 uiappearance
source share
6 answers

The very easy hack I adapted , which uses the iOS 5 appearance proxy , is as follows (of course, the advantage of the proxy server is a global change for all navigation bars):

 [[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(-400.f, 0) forBarMetrics:UIBarMetricsDefault]; 

This method is available in the iOS 5 SDK, so no worries.


EDIT

To avoid image stretching, use the following:

 UIImage* image = [UIImage imageNamed:@"back"]; return [image resizableImageWithCapInsets:UIEdgeInsetsMake(0, image.size.width, 0, 0)]; 
+9
source share

From what I can tell, you are setting the proxy correctly. The problem here is setting up a new name for the back button.

To do this, create a custom button with your behavior and use it as your new back button. Set this before you click or place the specified view controller, e.g. in init

 UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStyleBordered target:nil action:nil]; [self.navigationItem setBackBarButtonItem: newBackButton]; 
+4
source share
 UIImage *image1 = [UIImage imageNamed:@"image.png"]; [[UIBarButtonItem appearance] setBackButtonBackgroundImage:image1 forState:UIControlStateNormal barMetrics:UIBarMetricsDefault]; 

The above code is used to set the bacground image in the back button.

0
source share

as I understand it, you are asking how to change the button title.

that's how i always do it

 self.navigationItem.backBarButtonItem.title=@"My Title"; 

I think you can set it as empty without specifying a single name

 self.navigationItem.backBarButtonItem.title=@""; 

Be sure to call this function before clicking on the new view.

0
source share

I have not tried it, but I think this should work ... Put this on you viewdidLoad, I hope this is what you are looking for.

 UIBarButtonItem *backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:nil action:nil]; self.navigationItem.backBarButtonItem = backBarButtonItem; [backBarButtonItem release]; 
0
source share

Just add this line after the code you already wrote:

 [[UIBarButtonItem appearance] setTitle:@""]; 

Hope this works.

-4
source share

All Articles