alex
alex

Reputation: 1

UIBarBUttonItem image

I have a toolbar created programaticaly with 3 buttons (only 1 shown here). After a lot of Googling I was able to set a nice background image but now I don't know where to put
the code for the action: target:self action:@selector(pressButton3:) method. So I have a non-working button with nice colorful image. I've tried a lot of examples and if the button is working the image is not working and vice versa. Please help.

//Add buttons
UIImage *buttonImage = [UIImage imageNamed:@"mapp.png"];

UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setImage:buttonImage forState:UIControlStateNormal];
button.frame = CGRectMake(0, 0, buttonImage.size.width, buttonImage.size.height);

UIBarButtonItem *systemItem1 = [[UIBarButtonItem alloc] initWithCustomView:button];
[systemItem1 initWithBarButtonSystemItem:UIBarButtonItemStylePlain target:self action:@selector(pressButton1:)];

//add to array
 NSArray *items = [NSArray arrayWithObjects: systemItem1, nil];

Upvotes: 0

Views: 1132

Answers (1)

adriaan
adriaan

Reputation: 1594

I think you're button should work if you add:

[button addTarget:self action:@selector(pressButton1:) forControlEvents:UIControlEventTouchUpInside];

And remove the line:

[systemItem1 initWithBarButtonSystemItem:UIBarButtonItemStylePlain target:self action:@selector(pressButton1:)];

Upvotes: 1

Related Questions