0

I'm trying to add a custom button (shape and color) to my UIToolBar, but it comes out much differently than it should.

What button looks like:

enter image description here

What it looks like in the bar:

enter image description here

Here's the code I used to add it:

    UIImage *backButtonImage = [UIImage imageNamed:@"back-button.png"];
    UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithImage:backButtonImage style:UIBarButtonItemStylePlain target:self action:@selector(backButtonTapped)];
    [toolBarItems addObject:backButton];

What exactly am I doing wrong here?

user212541
  • 1,878
  • 1
  • 21
  • 30

1 Answers1

5

Try using initWithCustomView: instead of the other initialization method

So you should first create a UIButton with the custom image and selector you want and then use this piece of code

UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithCustomView:yourButton];
[toolBarItems addObject:backButton];
lostInTransit
  • 70,519
  • 61
  • 198
  • 274