-8

I believe I have tried all other SO solutions for this matter.

I use the following code to change the background image of my navigationbar backbutton.

UIImage *image = [UIImage imageNamed:@"standard_bt.png"];
        [[UIBarButtonItem appearance] setBackButtonBackgroundImage:image forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];

This makes the button appear like this:

enter image description here

Without this code, it appears like this:

enter image description here

Now, I would like the background image from the first picture, with the backbutton shape of the second picture.

Note: I would like to achieve this without having to modify the image named "standard_bt.png"

How do I do that? Is that possible?

Eyeball
  • 3,267
  • 2
  • 26
  • 50

2 Answers2

1

You have already done the right thing.

iOS SDK doesn't provide a convenience method to change the shape of an UIImage object according to the standard backbutton's shape.

That said, the answer is: no, you can not realize a shaped backbutton with your customization without changing the button's background image itself.

Computerspezl
  • 344
  • 1
  • 7
1

create a custom button with your button image. and add to navigation bar left.

it's like below

UIImage *menuImage = [UIImage imageNamed:@"bar.png"];
    UIButton *menuButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, menuImage.size.width, menuImage.size.height)];
    menuButton.backgroundColor = [UIColor colorWithPatternImage:menuImage];
    UIBarButtonItem *customBarButtonItem_left = [[UIBarButtonItem alloc] initWithCustomView:menuButton];
    [menuButton addTarget:self action:@selector(CallBack:) forControlEvents:UIControlEventTouchDown];
    self.navigationItem.leftBarButtonItem = customBarButtonItem_left;
dhaya
  • 1,522
  • 13
  • 21