Reputation: 31
I'm trying to set image to rightBarButtonItem.
I tried to do this 2 ways:
/* first way */
UIButton *button1 = [[UIButton alloc] init];
button1.frame=CGRectMake(0,0,105,30);
[button1 setBackgroundImage:[UIImage imageNamed: @"image.png"] forState:UIControlStateNormal];
[button1 addTarget:self action:@selector(rightBarButtonItemTapped) forControlEvents:UIControlEventTouchUpInside];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:button1];
/* second way */
UIBarButtonItem *rightBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"image"]
style:UIBarButtonItemStyleBordered
target:self
action:@selector(rightBarButtonItemTapped)];
P.S. When I tap right side of navigation bar I see that rightBarButtonItemTapped method invoked.
Upvotes: 0
Views: 46
Reputation: 93
You can set an image to a bar button using the attribute inspector.
Upvotes: 1